Skip to content

Commit c301c63

Browse files
committed
feat: radio add disabled context
1 parent e04f73d commit c301c63

File tree

4 files changed

+39
-13
lines changed

4 files changed

+39
-13
lines changed

components/radio/Group.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ import classNames from '../_util/classNames';
44
import PropTypes from '../_util/vue-types';
55
import Radio from './Radio';
66
import useConfigInject from '../config-provider/hooks/useConfigInject';
7-
import { tuple } from '../_util/type';
7+
import { booleanType, stringType, arrayType, functionType } from '../_util/type';
88
import type { RadioChangeEvent, RadioGroupButtonStyle, RadioGroupOptionType } from './interface';
99
import { useInjectFormItemContext } from '../form/FormItemContext';
1010
import { useProvideRadioGroupContext } from './context';
11-
import { booleanType, stringType, arrayType, functionType } from '../_util/type';
1211

1312
// CSSINJS
1413
import useStyle from './style';
1514

16-
const RadioGroupSizeTypes = tuple('large', 'default', 'small');
15+
const RadioGroupSizeTypes = ['large', 'default', 'small'] as const;
1716

1817
export type RadioGroupSize = (typeof RadioGroupSizeTypes)[number];
1918

@@ -28,7 +27,7 @@ export type RadioGroupChildOption = {
2827
export const radioGroupProps = () => ({
2928
prefixCls: String,
3029
value: PropTypes.any,
31-
size: PropTypes.oneOf(RadioGroupSizeTypes),
30+
size: stringType<RadioGroupSize>(),
3231
options: arrayType<Array<string | RadioGroupChildOption | number>>(),
3332
disabled: booleanType(),
3433
name: String,

components/radio/Radio.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { booleanType, functionType } from '../_util/type';
1313

1414
// CSSINJS
1515
import useStyle from './style';
16+
import { useInjectDisabled } from '../config-provider/DisabledContext';
1617

1718
export const radioProps = () => ({
1819
prefixCls: String,
@@ -45,12 +46,13 @@ export default defineComponent({
4546
const radioGroupContext = useInjectRadioGroupContext();
4647
const vcCheckbox = ref<HTMLElement>();
4748

48-
const { prefixCls: radioPrefixCls, direction } = useConfigInject('radio', props);
49+
const { prefixCls: radioPrefixCls, direction, disabled } = useConfigInject('radio', props);
4950
const prefixCls = computed(() =>
5051
radioGroupContext?.optionType.value === 'button' || radioOptionTypeContext === 'button'
5152
? `${radioPrefixCls.value}-button`
5253
: radioPrefixCls.value,
5354
);
55+
const contextDisabled = useInjectDisabled();
5456

5557
// Style
5658
const [wrapSSR, hashId] = useStyle(radioPrefixCls);
@@ -88,6 +90,7 @@ export default defineComponent({
8890
prefixCls: prefixCls.value,
8991
id,
9092
...omit(restProps, ['onUpdate:checked', 'onUpdate:value']),
93+
disabled: disabled.value ?? contextDisabled.value,
9194
};
9295

9396
if (radioGroup) {

components/radio/demo/disabled.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ Radio unavailable.
1818
<template>
1919
<div>
2020
<a-radio v-model:checked="checked1" :disabled="disabled">Disabled</a-radio>
21-
<br />
2221
<a-radio v-model:checked="checked2" :disabled="disabled">Disabled</a-radio>
23-
<div :style="{ marginTop: 20 }">
22+
<br />
23+
<div style="margin-top: 16px">
2424
<a-button type="primary" @click="toggleDisabled">Toggle disabled</a-button>
2525
</div>
2626
</div>
@@ -30,7 +30,7 @@ import { defineComponent, ref } from 'vue';
3030
export default defineComponent({
3131
setup() {
3232
const disabled = ref<boolean>(true);
33-
const checked1 = ref<boolean>(false);
33+
const checked1 = ref<boolean>(true);
3434
const checked2 = ref<boolean>(false);
3535
3636
const toggleDisabled = () => {

site/debugger/demo/demo.vue

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
<template>
2-
<a-alert message="Success Tips" type="success" show-icon closable>
3-
<template #action>
4-
<a-button v-if="false" size="small" type="text">UNDO</a-button>
5-
</template>
6-
</a-alert>
2+
<div>
3+
<a-radio v-model:checked="checked1" :disabled="disabled">Disabled</a-radio>
4+
<a-radio v-model:checked="checked2" :disabled="disabled">Disabled</a-radio>
5+
<br />
6+
<div style="margin-top: 16px">
7+
<a-button type="primary" @click="toggleDisabled">Toggle disabled</a-button>
8+
</div>
9+
</div>
710
</template>
11+
<script lang="ts">
12+
import { defineComponent, ref } from 'vue';
13+
export default defineComponent({
14+
setup() {
15+
const disabled = ref<boolean>(true);
16+
const checked1 = ref<boolean>(false);
17+
const checked2 = ref<boolean>(false);
18+
19+
const toggleDisabled = () => {
20+
disabled.value = !disabled.value;
21+
};
22+
23+
return {
24+
disabled,
25+
checked1,
26+
checked2,
27+
toggleDisabled,
28+
};
29+
},
30+
});
31+
</script>

0 commit comments

Comments
 (0)