From c301c63e8bca928a33af72c781b55fbefbefd49d Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Tue, 21 Feb 2023 12:06:31 +0800 Subject: [PATCH] feat: radio add disabled context --- components/radio/Group.tsx | 7 +++--- components/radio/Radio.tsx | 5 ++++- components/radio/demo/disabled.vue | 6 +++--- site/debugger/demo/demo.vue | 34 +++++++++++++++++++++++++----- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/components/radio/Group.tsx b/components/radio/Group.tsx index 87774bb27..958381101 100644 --- a/components/radio/Group.tsx +++ b/components/radio/Group.tsx @@ -4,16 +4,15 @@ import classNames from '../_util/classNames'; import PropTypes from '../_util/vue-types'; import Radio from './Radio'; import useConfigInject from '../config-provider/hooks/useConfigInject'; -import { tuple } from '../_util/type'; +import { booleanType, stringType, arrayType, functionType } from '../_util/type'; import type { RadioChangeEvent, RadioGroupButtonStyle, RadioGroupOptionType } from './interface'; import { useInjectFormItemContext } from '../form/FormItemContext'; import { useProvideRadioGroupContext } from './context'; -import { booleanType, stringType, arrayType, functionType } from '../_util/type'; // CSSINJS import useStyle from './style'; -const RadioGroupSizeTypes = tuple('large', 'default', 'small'); +const RadioGroupSizeTypes = ['large', 'default', 'small'] as const; export type RadioGroupSize = (typeof RadioGroupSizeTypes)[number]; @@ -28,7 +27,7 @@ export type RadioGroupChildOption = { export const radioGroupProps = () => ({ prefixCls: String, value: PropTypes.any, - size: PropTypes.oneOf(RadioGroupSizeTypes), + size: stringType(), options: arrayType>(), disabled: booleanType(), name: String, diff --git a/components/radio/Radio.tsx b/components/radio/Radio.tsx index d081a15d0..e09206ec3 100644 --- a/components/radio/Radio.tsx +++ b/components/radio/Radio.tsx @@ -13,6 +13,7 @@ import { booleanType, functionType } from '../_util/type'; // CSSINJS import useStyle from './style'; +import { useInjectDisabled } from '../config-provider/DisabledContext'; export const radioProps = () => ({ prefixCls: String, @@ -45,12 +46,13 @@ export default defineComponent({ const radioGroupContext = useInjectRadioGroupContext(); const vcCheckbox = ref(); - const { prefixCls: radioPrefixCls, direction } = useConfigInject('radio', props); + const { prefixCls: radioPrefixCls, direction, disabled } = useConfigInject('radio', props); const prefixCls = computed(() => radioGroupContext?.optionType.value === 'button' || radioOptionTypeContext === 'button' ? `${radioPrefixCls.value}-button` : radioPrefixCls.value, ); + const contextDisabled = useInjectDisabled(); // Style const [wrapSSR, hashId] = useStyle(radioPrefixCls); @@ -88,6 +90,7 @@ export default defineComponent({ prefixCls: prefixCls.value, id, ...omit(restProps, ['onUpdate:checked', 'onUpdate:value']), + disabled: disabled.value ?? contextDisabled.value, }; if (radioGroup) { diff --git a/components/radio/demo/disabled.vue b/components/radio/demo/disabled.vue index 9ce3a216b..6d44c7375 100644 --- a/components/radio/demo/disabled.vue +++ b/components/radio/demo/disabled.vue @@ -18,9 +18,9 @@ Radio unavailable.