Skip to content

Commit 1b5b7f2

Browse files
authored
feat(Radio): radio options support radio button (#3402)
* fix(TimePicker): fixed only support hh:mm format * fix(TimePicker): disabled position only is start * fix(Upload): fixed vue error on uploadPastedFiles is false * docs: add readonly in api * feat(RadioGroup): 单选组使用options时 支持button 模式
1 parent 2994ef8 commit 1b5b7f2

File tree

9 files changed

+152
-6
lines changed

9 files changed

+152
-6
lines changed

src/radio/_example-composition/group.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<t-space>
44
<t-radio-group name="city" v-model="value" :options="options" allowUncheck @change="onChange"></t-radio-group>
55
</t-space>
6-
76
<t-space>
87
<t-radio-group v-model="value2" @change="onChange2">
98
<t-radio value="1" allow-uncheck>选项一</t-radio>
@@ -12,13 +11,24 @@
1211
<t-radio value="4" disabled>选项四</t-radio>
1312
</t-radio-group>
1413
</t-space>
14+
<t-space>
15+
<t-radio-group
16+
name="city"
17+
v-model="value1"
18+
:options="options"
19+
theme="button"
20+
allowUncheck
21+
@change="onChange"
22+
></t-radio-group>
23+
</t-space>
1524
</t-space>
1625
</template>
1726

1827
<script setup>
1928
import { ref } from 'vue';
2029
2130
const value = ref('');
31+
const value1 = ref('');
2232
const value2 = ref('');
2333
const options = ref([
2434
{

src/radio/_example/group.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<t-space>
44
<t-radio-group name="city" v-model="value" :options="options" allowUncheck @change="onChange"></t-radio-group>
55
</t-space>
6-
76
<t-space>
87
<t-radio-group v-model="value2" @change="onChange2">
98
<t-radio value="1" allow-uncheck>选项一</t-radio>
@@ -12,6 +11,16 @@
1211
<t-radio value="4" disabled>选项四</t-radio>
1312
</t-radio-group>
1413
</t-space>
14+
<t-space>
15+
<t-radio-group
16+
name="city"
17+
v-model="value1"
18+
:options="options"
19+
theme="button"
20+
allowUncheck
21+
@change="onChange"
22+
></t-radio-group>
23+
</t-space>
1524
</t-space>
1625
</template>
1726

@@ -20,6 +29,7 @@ export default {
2029
data() {
2130
return {
2231
value: '',
32+
value1: '',
2333
value2: '',
2434
options: [
2535
{

src/radio/group.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
TdRadioGroupProps, RadioOptionObj, RadioOption, RadioValue,
77
} from './type';
88
import Radio from './radio';
9+
import RadioButton from './radio-button';
910
import { TNodeReturnValue } from '../common';
1011
import { emitEvent } from '../utils/event';
1112
import { getClassPrefixMixins } from '../config-provider/config-receiver';
@@ -17,7 +18,9 @@ const classPrefixMixins = getClassPrefixMixins('radio-group');
1718

1819
export default mixins(classPrefixMixins).extend({
1920
name: 'TRadioGroup',
20-
props: { ...props },
21+
props: {
22+
...props,
23+
},
2124

2225
components: {
2326
Radio,
@@ -52,8 +55,11 @@ export default mixins(classPrefixMixins).extend({
5255
if (isNumber(option) || isString(option)) {
5356
opt = { value: option, label: option.toString() };
5457
}
58+
59+
const RadioComponent = this.theme === 'button' ? RadioButton : Radio;
60+
5561
return (
56-
<Radio
62+
<RadioComponent
5763
props={option}
5864
key={`radio-group-options-${opt.value}-${index}`}
5965
name={this.name}
@@ -62,7 +68,7 @@ export default mixins(classPrefixMixins).extend({
6268
value={opt.value}
6369
>
6470
{typeof opt.label === 'function' ? opt.label(h) : opt.label}
65-
</Radio>
71+
</RadioComponent>
6672
);
6773
});
6874
}

src/radio/radio-group-props.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ export default {
2424
options: {
2525
type: Array as PropType<TdRadioGroupProps['options']>,
2626
},
27+
/** 组件风格 */
28+
theme: {
29+
type: String as PropType<TdRadioGroupProps['theme']>,
30+
default: 'radio' as TdRadioGroupProps['theme'],
31+
validator(val: TdRadioGroupProps['theme']): boolean {
32+
return ['radio', 'button'].includes(val);
33+
},
34+
},
2735
/** 组件尺寸【讨论中】 */
2836
size: {
2937
type: String as PropType<TdRadioGroupProps['size']>,

src/radio/radio.en-US.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ allowUncheck | Boolean | false | \- | N
3131
disabled | Boolean | undefined | \- | N
3232
name | String | - | \- | N
3333
options | Array | - | Typescript:`Array<RadioOption>` `type RadioOption = string \| number \| RadioOptionObj` `interface RadioOptionObj { label?: string \| TNode; value?: string \| number; disabled?: boolean }`[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts)[see more ts definition](https://github.com/Tencent/tdesign-vue/tree/develop/src/radio/type.ts) | N
34+
theme | String | radio | options:radio/button。 | N
3435
size | String | medium | options:small/medium/large。Typescript:`SizeEnum`[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
3536
value | String / Number / Boolean | - | `v-model` is supported。Typescript:`T` | N
3637
defaultValue | String / Number / Boolean | - | uncontrolled property。Typescript:`T` | N

src/radio/radio.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ allowUncheck | Boolean | false | 是否允许取消选中 | N
3131
disabled | Boolean | undefined | 是否禁用全部子单选框 | N
3232
name | String | - | HTML 元素原生属性 | N
3333
options | Array | - | 单选组件按钮形式。RadioOption 数据类型为 string 或 number 时,表示 label 和 value 值相同。TS 类型:`Array<RadioOption>` `type RadioOption = string \| number \| RadioOptionObj` `interface RadioOptionObj { label?: string \| TNode; value?: string \| number; disabled?: boolean }`[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts)[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/radio/type.ts) | N
34+
theme | String | radio | 组件风格,可选项:radio/button。 | N
3435
size | String | medium | 组件尺寸【讨论中】。可选项:small/medium/large。TS 类型:`SizeEnum`[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
3536
value | String / Number / Boolean | - | 选中的值。支持语法糖 `v-model`。TS 类型:`T` | N
3637
defaultValue | String / Number / Boolean | - | 选中的值。非受控属性。TS 类型:`T` | N

src/radio/type.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ export interface TdRadioGroupProps<T = RadioValue> {
9090
* @default outline
9191
*/
9292
variant?: 'outline' | 'primary-filled' | 'default-filled';
93+
94+
/**
95+
* 组件风格
96+
*/
97+
theme?: 'radio' | 'button';
9398
/**
9499
* 选中值发生变化时触发
95100
*/

test/snap/__snapshots__/csr.test.js.snap

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84880,6 +84880,111 @@ exports[`csr snapshot test > csr test ./src/radio/_example/group.vue 1`] = `
8488084880
</div>
8488184881
</div>
8488284882
</div>
84883+
<div
84884+
class="t-space-item"
84885+
>
84886+
<div
84887+
class="t-space t-space-horizontal"
84888+
style="gap: 16px;"
84889+
>
84890+
<div
84891+
class="t-space-item"
84892+
>
84893+
<div
84894+
class="t-radio-group t-size-m t-radio-group__outline"
84895+
>
84896+
<label
84897+
class="t-radio-button"
84898+
tabindex="0"
84899+
>
84900+
<input
84901+
class="t-radio-button__former"
84902+
data-allow-uncheck="true"
84903+
data-value="1"
84904+
name="city"
84905+
tabindex="-1"
84906+
type="radio"
84907+
value="1"
84908+
/>
84909+
<span
84910+
class="t-radio-button__input"
84911+
/>
84912+
<span
84913+
class="t-radio-button__label"
84914+
>
84915+
选项一
84916+
</span>
84917+
</label>
84918+
<label
84919+
class="t-radio-button"
84920+
tabindex="0"
84921+
>
84922+
<input
84923+
class="t-radio-button__former"
84924+
data-allow-uncheck="true"
84925+
data-value="2"
84926+
name="city"
84927+
tabindex="-1"
84928+
type="radio"
84929+
value="2"
84930+
/>
84931+
<span
84932+
class="t-radio-button__input"
84933+
/>
84934+
<span
84935+
class="t-radio-button__label"
84936+
>
84937+
选项二
84938+
</span>
84939+
</label>
84940+
<label
84941+
class="t-radio-button"
84942+
tabindex="0"
84943+
>
84944+
<input
84945+
class="t-radio-button__former"
84946+
data-allow-uncheck="true"
84947+
data-value="'3'"
84948+
name="city"
84949+
tabindex="-1"
84950+
type="radio"
84951+
value="3"
84952+
/>
84953+
<span
84954+
class="t-radio-button__input"
84955+
/>
84956+
<span
84957+
class="t-radio-button__label"
84958+
>
84959+
选项三
84960+
</span>
84961+
</label>
84962+
<label
84963+
class="t-radio-button"
84964+
tabindex="0"
84965+
>
84966+
<input
84967+
class="t-radio-button__former"
84968+
data-allow-uncheck="true"
84969+
data-value="'4'"
84970+
name="city"
84971+
tabindex="-1"
84972+
type="radio"
84973+
value="4"
84974+
/>
84975+
<span
84976+
class="t-radio-button__input"
84977+
/>
84978+
<span
84979+
class="t-radio-button__label"
84980+
>
84981+
选项四
84982+
</span>
84983+
</label>
84984+
</div>
84985+
</div>
84986+
</div>
84987+
</div>
8488384988
</div>
8488484989
`;
8488584990

0 commit comments

Comments
 (0)