From 52e09e404a074c4b323cec869283e156d670a99b Mon Sep 17 00:00:00 2001 From: jizai1125 <1414589221@qq.com> Date: Fri, 19 Aug 2022 16:23:56 +0800 Subject: [PATCH] fix(radio): fix warning when value prop type is boolean, close #3540 --- CHANGELOG.en-US.md | 4 ++++ CHANGELOG.zh-CN.md | 4 ++++ src/radio/demos/enUS/index.demo-entry.md | 6 +++--- src/radio/demos/zhCN/index.demo-entry.md | 6 +++--- src/radio/src/RadioGroup.tsx | 12 ++++++++---- src/radio/src/interface.ts | 4 ++-- src/radio/src/use-radio.ts | 4 ++-- 7 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index 0b4932d4b22..a80e7fe8b6a 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -1,5 +1,9 @@ # CHANGELOG +## NEXT_VERSION + +- Fix `n-radio` fix warning when value prop type is boolean, close (#3540)[https://github.com/tusen-ai/naive-ui/issues/3540]. + ## 2.32.2 ### Fixes diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index 683f94bbda9..8ec5eabc793 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -1,5 +1,9 @@ # CHANGELOG +## NEXT_VERSION + +- 修复 `n-radio` 当 `value` 属性为布尔值时报警告, 关闭 [#3540](https://github.com/tusen-ai/naive-ui/issues/3540) + ## 2.32.2 ### Fixes diff --git a/src/radio/demos/enUS/index.demo-entry.md b/src/radio/demos/enUS/index.demo-entry.md index 9ada576d9b7..92678043692 100644 --- a/src/radio/demos/enUS/index.demo-entry.md +++ b/src/radio/demos/enUS/index.demo-entry.md @@ -25,7 +25,7 @@ size.vue | label | `string` | `undefined` | Radio label. If not set, render default slot content, if both, use default slot content first. | 2.28.0 | | name | `string` | `undefined` | The name attribute of the radio element. If not set, name of `radio-group` will be used. | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Size. | | -| value | `string \| number` | `'on'` | Checked value. | | +| value | `string \| number \| boolean` | `'on'` | Checked value. | | | on-update:checked | `(check: boolean) => void` | `undefined` | Callback method triggered when a selection change occurs. | | ### RadioGroup Props @@ -35,6 +35,6 @@ size.vue | disabled | `boolean` | `false` | Disabled state. | | name | `string` | `undefined` | The name attribute of the radio elements inside the group. | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Size. | -| value | `string \| number \| null` | `null` | Checked value. | -| default-value | `string \| number \| null` | `null` | Default checked value. | +| value | `string \| number \| boolean \| null` | `null` | Checked value. | +| default-value | `string \| number \| boolean \| null` | `null` | Default checked value. | | on-update:value | `(value: string) => void` | `undefined` | Callback method triggered when a selection change occurs. | diff --git a/src/radio/demos/zhCN/index.demo-entry.md b/src/radio/demos/zhCN/index.demo-entry.md index c66b28ba969..9bbe966d287 100644 --- a/src/radio/demos/zhCN/index.demo-entry.md +++ b/src/radio/demos/zhCN/index.demo-entry.md @@ -27,7 +27,7 @@ rtl-debug.vue | label | `string` | `undefined` | 标签 | 2.28.0 | | name | `string` | `undefined` | 单选按钮 radio 元素的 name 属性。如果没有设定会使用 `n-radio-group` 的 `name` | | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | 大小 | | -| value | `string \| number` | `'on'` | 选中的值 | | +| value | `string \| number \| boolean` | `'on'` | 选中的值 | | | on-update:checked | `(checked: boolean) => void` | `undefined` | 发生变化时触发的回调方法 | | ### RadioGroup Props @@ -37,6 +37,6 @@ rtl-debug.vue | disabled | `boolean` | `false` | 禁用状态 | | name | `string` | `undefined` | 选项组内部 radio 元素的 name 属性 | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | 大小 | -| value | `string \| number \| null` | `null` | 选中的值 | -| default-value | `string \| number \| null` | `null` | 默认选中的值 | +| value | `string \| number \| boolean \| null` | `null` | 选中的值 | +| default-value | `string \| number \| boolean \| null` | `null` | 默认选中的值 | | on-update:value | `(value: string) => void` | `undefined` | 发生变化时触发的回调方法 | diff --git a/src/radio/src/RadioGroup.tsx b/src/radio/src/RadioGroup.tsx index 8c155ac7e55..3b343c99773 100644 --- a/src/radio/src/RadioGroup.tsx +++ b/src/radio/src/RadioGroup.tsx @@ -25,7 +25,7 @@ import { useRtl } from '../../_mixins/use-rtl' function mapSlot ( defaultSlot: VNode[], - value: string | number | null, + value: string | number | boolean | null, clsPrefix: string ): { children: VNodeChild[] @@ -100,9 +100,13 @@ function mapSlot ( export const radioGroupProps = { ...(useTheme.props as ThemeProps), name: String, - value: [String, Number] as PropType, + value: [String, Number, Boolean] as PropType< + string | number | boolean | null + >, defaultValue: { - type: [String, Number] as PropType, + type: [String, Number, Boolean] as PropType< + string | number | boolean | null + >, default: null }, size: String as PropType<'small' | 'medium' | 'large'>, @@ -145,7 +149,7 @@ export default defineComponent({ controlledValueRef, uncontrolledValueRef ) - function doUpdateValue (value: string | number): void { + function doUpdateValue (value: string | number | boolean): void { const { onUpdateValue, 'onUpdate:value': _onUpdateValue } = props if (onUpdateValue) { call(onUpdateValue as OnUpdateValueImpl, value) diff --git a/src/radio/src/interface.ts b/src/radio/src/interface.ts index 23715021ff6..b94f2067bfc 100644 --- a/src/radio/src/interface.ts +++ b/src/radio/src/interface.ts @@ -1,3 +1,3 @@ -export type OnUpdateValue = (value: string & number) => void +export type OnUpdateValue = (value: string & number & boolean) => void -export type OnUpdateValueImpl = (value: string | number) => void +export type OnUpdateValueImpl = (value: string | number | boolean) => void diff --git a/src/radio/src/use-radio.ts b/src/radio/src/use-radio.ts index d69cdb34a58..5c3badc1ca9 100644 --- a/src/radio/src/use-radio.ts +++ b/src/radio/src/use-radio.ts @@ -16,7 +16,7 @@ import { OnUpdateValue, OnUpdateValueImpl } from './interface' const radioProps = { name: String, value: { - type: [String, Number] as PropType, + type: [String, Number, Boolean] as PropType, default: 'on' }, checked: { @@ -53,7 +53,7 @@ const radioProps = { export interface RadioGroupInjection { mergedClsPrefixRef: Ref nameRef: Ref - valueRef: Ref + valueRef: Ref mergedSizeRef: Ref<'small' | 'medium' | 'large'> disabledRef: Ref doUpdateValue: OnUpdateValue