From 295dfd32a7181d6d69ad1026194354e4f449c57e Mon Sep 17 00:00:00 2001 From: betavs <34408516+betavs@users.noreply.github.com> Date: Thu, 17 Aug 2023 11:17:56 +0800 Subject: [PATCH] feat(radio): enable readonly (#2292) --- src/radio-group/radio-group.wxml | 1 + src/radio-group/type.ts | 1 + src/radio/README.en-US.md | 1 + src/radio/README.md | 1 + src/radio/props.ts | 5 +++++ src/radio/radio.ts | 2 +- src/radio/type.ts | 8 ++++++++ 7 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/radio-group/radio-group.wxml b/src/radio-group/radio-group.wxml index 671705e56..4020f53c4 100644 --- a/src/radio-group/radio-group.wxml +++ b/src/radio-group/radio-group.wxml @@ -15,6 +15,7 @@ content="{{item.content || ''}}" allow-uncheck="{{item.allowUncheck || false}}" content-disabled="{{item.contentDisabled || false}}" + readonly="{{item.readonly || false}}" disabled="{{item.disabled || false}}" icon="{{item.icon || icon}}" placement="{{item.placement || placement}}" diff --git a/src/radio-group/type.ts b/src/radio-group/type.ts index ef77eeb4b..dc666c07e 100644 --- a/src/radio-group/type.ts +++ b/src/radio-group/type.ts @@ -89,6 +89,7 @@ export type RadioOption = string | number | RadioOptionObj; export interface RadioOptionObj { label?: string; value?: string | number; + readonly?: boolean; disabled?: boolean; allowUncheck?: boolean; } diff --git a/src/radio/README.en-US.md b/src/radio/README.en-US.md index 6f49f9e21..97fa9df19 100644 --- a/src/radio/README.en-US.md +++ b/src/radio/README.en-US.md @@ -33,6 +33,7 @@ name | type | default | description | required -- | -- | -- | -- | -- placement | String | left | options:left/right | N borderless | Boolean | false | \- | N +readonly | Boolean | false | \- | N disabled | Boolean | undefined | \- | N icon | String / Array | 'circle' | Typescript:`'circle' | 'line' | Array` | N keys | Object | - | Typescript:`KeysType` | N diff --git a/src/radio/README.md b/src/radio/README.md index 000532f25..03dbca0db 100644 --- a/src/radio/README.md +++ b/src/radio/README.md @@ -59,6 +59,7 @@ checked | Boolean | false | 是否选中 | N default-checked | Boolean | undefined | 是否选中。非受控属性 | N content | String / Slot | - | 单选内容 | N content-disabled | Boolean | false | 是否禁用组件内容(content)触发选中 | N +readonly | Boolean | false | 只读状态 | N disabled | Boolean | undefined | 是否为禁用态 | N icon | String / Array / Slot | 'circle' | 自定义选中图标和非选中图标。使用 Array 时表示:`[选中态图标,非选中态图标]`。使用 String 时,值为 circle 表示填充型图标、值为 line 表示描边型图标、值为 dot 表示圆点图标,值为 slot 时使用插槽。TS 类型:`'circle' \| 'line' \| 'dot' \| Array` | N label | String / Slot | - | 主文案 | N diff --git a/src/radio/props.ts b/src/radio/props.ts index a51aa2848..cfe79076d 100644 --- a/src/radio/props.ts +++ b/src/radio/props.ts @@ -40,6 +40,11 @@ const props: TdRadioProps = { type: Boolean, value: false, }, + /** 只读状态 */ + readonly: { + type: Boolean, + value: false, + }, /** 是否为禁用态 */ disabled: { type: Boolean, diff --git a/src/radio/radio.ts b/src/radio/radio.ts index 799e23ee4..b97d33693 100644 --- a/src/radio/radio.ts +++ b/src/radio/radio.ts @@ -65,7 +65,7 @@ export default class Radio extends SuperComponent { methods = { handleTap(e) { - if (this.data.disabled) return; + if (this.data.disabled || this.data.readonly) return; const { target } = e.currentTarget.dataset; diff --git a/src/radio/type.ts b/src/radio/type.ts index d4af04476..2ae247bb7 100644 --- a/src/radio/type.ts +++ b/src/radio/type.ts @@ -68,6 +68,14 @@ export interface TdRadioProps { type: StringConstructor; value?: string; }; + /** + * 只读状态 + * @default false + */ + readonly?: { + type: BooleanConstructor; + value?: boolean; + }; /** * 是否为禁用态 */