Skip to content

Commit 84341ef

Browse files
committed
feat: radio support rtl #4720
1 parent cf3fe6b commit 84341ef

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

components/radio/Group.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { provide, nextTick, defineComponent, ref, watch, onBeforeMount } from 'vue';
1+
import { provide, nextTick, defineComponent, ref, watch } from 'vue';
22
import type { PropType, ExtractPropTypes } from 'vue';
33
import classNames from '../_util/classNames';
44
import PropTypes from '../_util/vue-types';
@@ -44,8 +44,8 @@ export default defineComponent({
4444
emits: ['update:value', 'change'],
4545
setup(props, { slots, emit }) {
4646
const formItemContext = useInjectFormItemContext();
47-
const { prefixCls } = useConfigInject('radio', props);
48-
const stateValue = ref(props.value === undefined ? props.defaultValue : props.value);
47+
const { prefixCls, direction, size } = useConfigInject('radio', props);
48+
const stateValue = ref(props.value);
4949
const updatingValue = ref<boolean>(false);
5050
watch(
5151
() => props.value,
@@ -73,7 +73,7 @@ export default defineComponent({
7373
updatingValue.value = false;
7474
});
7575
};
76-
76+
7777
provide('radioGroupContext', {
7878
onRadioChange,
7979
stateValue,
@@ -86,7 +86,8 @@ export default defineComponent({
8686
const groupPrefixCls = `${prefixCls.value}-group`;
8787

8888
const classString = classNames(groupPrefixCls, `${groupPrefixCls}-${buttonStyle}`, {
89-
[`${groupPrefixCls}-${props.size}`]: props.size,
89+
[`${groupPrefixCls}-${size.value}`]: size.value,
90+
[`${groupPrefixCls}-rtl`]: direction.value === 'rtl',
9091
});
9192

9293
let children = null;

components/radio/Radio.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export default defineComponent({
3131
setup(props, { emit, expose, slots }) {
3232
const formItemContext = useInjectFormItemContext();
3333
const vcCheckbox = ref<HTMLElement>();
34-
const radioGroupContext = inject<RadioGroupContext>('radioGroupContext');
35-
const { prefixCls } = useConfigInject('radio', props);
34+
const radioGroupContext = inject<RadioGroupContext>('radioGroupContext', undefined);
35+
const { prefixCls, direction } = useConfigInject('radio', props);
3636

3737
const focus = () => {
3838
vcCheckbox.value.focus();
@@ -81,6 +81,7 @@ export default defineComponent({
8181
[`${prefixCls.value}-wrapper`]: true,
8282
[`${prefixCls.value}-wrapper-checked`]: rProps.checked,
8383
[`${prefixCls.value}-wrapper-disabled`]: rProps.disabled,
84+
[`${prefixCls.value}-wrapper-rtl`]: direction.value === 'rtl',
8485
});
8586

8687
return (

components/radio/RadioButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineComponent({
99
props: radioProps,
1010
setup(props: RadioProps, { slots }) {
1111
const { prefixCls } = useConfigInject('radio-button', props);
12-
const radioGroupContext = inject<RadioGroupContext>('radioGroupContext');
12+
const radioGroupContext = inject<RadioGroupContext>('radioGroupContext', undefined);
1313

1414
return () => {
1515
const rProps: RadioProps = {

0 commit comments

Comments
 (0)