Skip to content

Commit

Permalink
fix(radio): update input uncontrolled value (#5186)
Browse files Browse the repository at this point in the history
Co-authored-by: 07akioni <[email protected]>
  • Loading branch information
chenglu4343 and 07akioni authored Dec 20, 2023
1 parent d919d01 commit 9c03ff7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- 修复 `n-data-table` 总结栏有未设定的列时,会抛出 error
- 修复 `n-drawer``on-mask-click` 属性可能被触发多次
- 修复 `n-tree` 属性 `data` 当数据源`data`按一定场景多次发生切换时,动画处理的一些逻辑会导致渲染展示的数据出错,关闭 [#5217](https://github.com/tusen-ai/naive-ui/issues/5217)
- 修复 `n-radio` value 值取消更新后,input 原生 checked 值未更新,关闭 [#5184](https://github.com/tusen-ai/naive-ui/issues/5184)

### Features

Expand Down
11 changes: 9 additions & 2 deletions src/radio/src/use-radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
type PropType,
type Ref,
type ComputedRef,
watchEffect
watchEffect,
nextTick
} from 'vue'
import { useMemo, useMergedState } from 'vooks'
import { useConfig, useFormItem } from '../../_mixins'
Expand Down Expand Up @@ -107,7 +108,7 @@ function setup (props: ExtractPropTypes<typeof radioBaseProps>): UseRadio {
}
})
const { mergedSizeRef, mergedDisabledRef } = formItem
const inputRef = ref<HTMLElement | null>(null)
const inputRef = ref<HTMLInputElement | null>(null)
const labelRef = ref<HTMLElement | null>(null)
const NRadioGroup = inject(radioGroupInjectionKey, null)
const uncontrolledCheckedRef = ref(props.defaultChecked)
Expand Down Expand Up @@ -149,6 +150,12 @@ function setup (props: ExtractPropTypes<typeof radioBaseProps>): UseRadio {
}
function handleRadioInputChange (): void {
toggle()
// eslint-disable-next-line @typescript-eslint/no-floating-promises
nextTick(() => {
if (inputRef.value) {
inputRef.value.checked = mergedCheckedRef.value
}
})
}
function handleRadioInputBlur (): void {
focusRef.value = false
Expand Down

0 comments on commit 9c03ff7

Please sign in to comment.