Skip to content

Commit 1fa0568

Browse files
authored
feat(RadioGroup): support allow-uncheck props (#3140)
* fix(Radio): update style * feat(Radio): add allow-uncheck props for radio-group * test: update snapshots
1 parent d8738f7 commit 1fa0568

File tree

12 files changed

+41
-16
lines changed

12 files changed

+41
-16
lines changed

src/radio-group/props.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
import { TdRadioGroupProps } from './type';
88
const props: TdRadioGroupProps = {
9+
/** 是否允许取消选中 */
10+
allowUncheck: {
11+
type: Boolean,
12+
value: false,
13+
},
914
/** 是否开启无边框模式 */
1015
borderless: {
1116
type: Boolean,

src/radio-group/radio-group.wxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
class="{{prefix}}-radio-option"
88
data-index="{{index}}"
99
data-value="{{item.value}}"
10-
data-allow-uncheck="{{item.allowUncheck || false}}"
10+
data-allow-uncheck="{{item.allowUncheck || allowUncheck}}"
1111
block="{{item.block || true}}"
1212
label="{{item.label || ''}}"
1313
value="{{item.value}}"
1414
checked="{{item.checked || false}}"
1515
content="{{item.content || ''}}"
16-
allow-uncheck="{{item.allowUncheck || false}}"
16+
allow-uncheck="{{item.allowUncheck || allowUncheck}}"
1717
content-disabled="{{item.contentDisabled || false}}"
1818
readonly="{{item.readonly || false}}"
1919
disabled="{{item.disabled || false}}"

src/radio-group/type.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
import { KeysType } from '../common/common';
88

99
export interface TdRadioGroupProps<T = RadioValue> {
10+
/**
11+
* 是否允许取消选中
12+
* @default false
13+
*/
14+
allowUncheck?: {
15+
type: BooleanConstructor;
16+
value?: boolean;
17+
};
1018
/**
1119
* 是否开启无边框模式
1220
* @default false

src/radio/README.en-US.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ value | String / Number / Boolean | false | Typescript:`T` `type RadioValue =
2929
name | params | description
3030
-- | -- | --
3131
change | `(checked: boolean)` | \-
32+
3233
### Radio External Classes
3334

3435
className | Description
@@ -46,6 +47,7 @@ name | type | default | description | required
4647
-- | -- | -- | -- | --
4748
style | Object | - | CSS(Cascading Style Sheets) | N
4849
custom-style | Object | - | CSS(Cascading Style Sheets),used to set style on virtual component | N
50+
allow-uncheck | Boolean | false | \- | N
4951
borderless | Boolean | false | \- | N
5052
disabled | Boolean | undefined | \- | N
5153
icon | String / Array | 'circle' | Typescript:`'circle' \| 'line' \| 'dot' \| Array<string>` | N

src/radio/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ value | String / Number / Boolean | false | 单选按钮的值。TS 类型:`T`
8282
名称 | 参数 | 描述
8383
-- | -- | --
8484
change | `(checked: boolean)` | 值变化时触发
85+
8586
### Radio External Classes
8687

8788
类名 | 描述
@@ -99,6 +100,7 @@ t-class-label | 标签样式类
99100
-- | -- | -- | -- | --
100101
style | Object | - | 样式 | N
101102
custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N
103+
allow-uncheck | Boolean | false | 是否允许取消选中 | N
102104
borderless | Boolean | false | 是否开启无边框模式 | N
103105
disabled | Boolean | undefined | 是否禁用全部子单选框 | N
104106
icon | String / Array | 'circle' | 自定义选中图标和非选中图标。示例:[选中态图标,非选中态图标]。使用 String 时,值为 circle 表示填充型图标、值为 line 表示描边型图标、值为 dot 表示圆点图标;仅在使用 options 时生效。TS 类型:`'circle' \| 'line' \| 'dot' \| Array<string>` | N

src/radio/__test__/__snapshots__/demo.test.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`Radio Radio align demo works fine 1`] = `
44
<align>
55
<t-radio
6+
allowUncheck="{{true}}"
67
defaultChecked="{{true}}"
78
label="单选"
89
value="radio1"
@@ -11,6 +12,7 @@ exports[`Radio Radio align demo works fine 1`] = `
1112
class="block"
1213
/>
1314
<t-radio
15+
allowUncheck="{{true}}"
1416
defaultChecked="{{true}}"
1517
label="单选"
1618
placement="right"
@@ -22,6 +24,7 @@ exports[`Radio Radio align demo works fine 1`] = `
2224
exports[`Radio Radio base demo works fine 1`] = `
2325
<base>
2426
<t-radio-group
27+
allowUncheck="{{true}}"
2528
options="{{
2629
Array [
2730
Object {
@@ -101,6 +104,7 @@ exports[`Radio Radio horizontal demo works fine 1`] = `
101104
exports[`Radio Radio special demo works fine 1`] = `
102105
<special>
103106
<t-radio-group
107+
allowUncheck="{{true}}"
104108
value="{{0}}"
105109
bind:change="onChange"
106110
>
@@ -212,6 +216,7 @@ exports[`Radio Radio status demo works fine 1`] = `
212216
exports[`Radio Radio theme demo works fine 1`] = `
213217
<theme>
214218
<t-radio
219+
allowUncheck="{{true}}"
215220
defaultChecked="{{true}}"
216221
icon="line"
217222
label="单选"
@@ -221,6 +226,7 @@ exports[`Radio Radio theme demo works fine 1`] = `
221226
style="height: 32rpx"
222227
/>
223228
<t-radio
229+
allowUncheck="{{true}}"
224230
defaultChecked="{{true}}"
225231
icon="dot"
226232
label="单选"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<t-radio value="radio1" label="单选" default-checked />
1+
<t-radio value="radio1" allow-uncheck label="单选" default-checked />
22

33
<view class="block"></view>
44

5-
<t-radio value="radio2" label="单选" placement="right" default-checked />
5+
<t-radio value="radio2" allow-uncheck label="单选" placement="right" default-checked />

src/radio/_example/base/index.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<t-radio-group bind:change="onChange" value="{{current}}" options="{{options}}" />
1+
<t-radio-group bind:change="onChange" allow-uncheck value="{{current}}" options="{{options}}" />

src/radio/_example/special/index.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<t-radio-group value="{{value}}" bind:change="onChange">
1+
<t-radio-group value="{{value}}" allow-uncheck bind:change="onChange">
22
<view wx:for="{{3}}" wx:key="index" class="card {{value == index ? 'card--active' : ''}}">
33
<t-icon wx:if="{{value == index}}" name="check" t-class="card__icon" />
44
<t-radio value="{{index}}" label="单选" content="描述信息描述信息描述信息描述信息描述信息" icon="none" borderless />
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<t-radio default-checked="{{true}}" icon="line" label="单选" />
1+
<t-radio default-checked="{{true}}" allow-uncheck icon="line" label="单选" />
22

33
<view class="gutter" style="height: 32rpx"></view>
44

5-
<t-radio default-checked="{{true}}" icon="dot" label="单选" />
5+
<t-radio default-checked="{{true}}" allow-uncheck icon="dot" label="单选" />

0 commit comments

Comments
 (0)