From df1ccb783f024cd0d124558171f27014f0c7a6c0 Mon Sep 17 00:00:00 2001 From: Vixalie Date: Sun, 24 Aug 2025 11:26:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(components):=20=E4=B8=BA=E5=A4=8D=E9=80=89?= =?UTF-8?q?=E6=A1=86=E5=92=8C=E5=8D=95=E9=80=89=E6=A1=86=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=AA=E8=AF=BB=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 CheckBoxProps、RadioProps 和 RadioGroupProps 接口中添加 readonly 属性 - 在 Check、Radio 和 RadioGroup 组件中实现只读逻辑 - 修改 handleClick 和 handleSelect 方法,增加对只读属性的判断 --- src/components/Check.tsx | 4 +++- src/components/Radio.tsx | 4 +++- src/components/RadioGroup.tsx | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/Check.tsx b/src/components/Check.tsx index cf94db7..db545af 100644 --- a/src/components/Check.tsx +++ b/src/components/Check.tsx @@ -17,6 +17,7 @@ interface CheckBoxProps { checked?: boolean; defaultChecked?: boolean; disabled?: boolean; + readonly?: boolean; onChange?: (checked?: boolean) => void; } @@ -35,6 +36,7 @@ const Check: ParentComponent = (props) => { const mProps = mergeProps[]>( { disabled: false, + readonly: false, }, props, ); @@ -54,7 +56,7 @@ const Check: ParentComponent = (props) => { }); const handleClick = () => { - if (mProps.disabled) { + if (mProps.disabled || mProps.readonly) { return; } setInternalChecked((prev) => !prev); diff --git a/src/components/Radio.tsx b/src/components/Radio.tsx index f5c4d83..d39380d 100644 --- a/src/components/Radio.tsx +++ b/src/components/Radio.tsx @@ -17,6 +17,7 @@ interface RadioProps { checked?: boolean; defaultChecked?: boolean; disabled?: boolean; + readonly?: boolean; onChange?: (value?: boolean) => void; } @@ -35,6 +36,7 @@ const Radio: ParentComponent = (props) => { const mProps = mergeProps[]>( { disabled: false, + readonly: false, }, props, ); @@ -54,7 +56,7 @@ const Radio: ParentComponent = (props) => { }); const handleClick = () => { - if (mProps.disabled) { + if (mProps.disabled || mProps.readonly) { return; } setInternalChecked((prev) => !prev); diff --git a/src/components/RadioGroup.tsx b/src/components/RadioGroup.tsx index 8a9da62..f16a96e 100644 --- a/src/components/RadioGroup.tsx +++ b/src/components/RadioGroup.tsx @@ -23,6 +23,7 @@ interface RadioGroupProps { value?: Option['value']; defalutValue?: Option['value']; disabled?: boolean; + readonly?: boolean; onChange?: (value?: Option['value']) => void; } @@ -31,6 +32,7 @@ const RadioGroup: Component = (props) => { { options: [], disabled: false, + readonly: false, }, props, ); @@ -50,7 +52,7 @@ const RadioGroup: Component = (props) => { }); const handleSelect = (value: Option['value']) => { - if (mProps.disabled) { + if (mProps.disabled || mProps.readonly) { return; } setSelectedValue(value); @@ -64,6 +66,7 @@ const RadioGroup: Component = (props) => { { handleSelect(option().value); }}>