11import type { ExtractPropTypes , PropType } from 'vue' ;
2- import { defineComponent , inject , ref } from 'vue' ;
2+ import { computed , defineComponent , ref } from 'vue' ;
33import PropTypes from '../_util/vue-types' ;
44import VcCheckbox from '../vc-checkbox/Checkbox' ;
55import classNames from '../_util/classNames' ;
66import useConfigInject from '../_util/hooks/useConfigInject' ;
7- import type { RadioChangeEvent , RadioGroupContext } from './interface' ;
8- import { useInjectFormItemContext } from '../form/FormItemContext' ;
7+ import type { RadioChangeEvent } from './interface' ;
8+ import { FormItemInputContext , useInjectFormItemContext } from '../form/FormItemContext' ;
99import omit from '../_util/omit' ;
1010import type { FocusEventHandler , MouseEventHandler } from '../_util/EventInterface' ;
11+ import { useInjectRadioGroupContext , useInjectRadioOptionTypeContext } from './context' ;
1112
1213export const radioProps = ( ) => ( {
1314 prefixCls : String ,
@@ -31,13 +32,19 @@ export type RadioProps = Partial<ExtractPropTypes<ReturnType<typeof radioProps>>
3132export default defineComponent ( {
3233 name : 'ARadio' ,
3334 props : radioProps ( ) ,
34- // emits: ['update:checked', 'update:value', 'change', 'blur', 'focus'],
3535 setup ( props , { emit, expose, slots } ) {
3636 const formItemContext = useInjectFormItemContext ( ) ;
37+ const formItemInputContext = FormItemInputContext . useInject ( ) ;
38+ const radioOptionTypeContext = useInjectRadioOptionTypeContext ( ) ;
39+ const radioGroupContext = useInjectRadioGroupContext ( ) ;
3740 const vcCheckbox = ref < HTMLElement > ( ) ;
38- const radioGroupContext = inject < RadioGroupContext > ( 'radioGroupContext' , undefined ) ;
39- const { prefixCls, direction } = useConfigInject ( 'radio' , props ) ;
4041
42+ const { prefixCls : radioPrefixCls , direction } = useConfigInject ( 'radio' , props ) ;
43+ const prefixCls = computed ( ( ) =>
44+ ( radioGroupContext ?. optionType . value || radioOptionTypeContext ) === 'button'
45+ ? `${ radioPrefixCls . value } -button`
46+ : radioPrefixCls . value ,
47+ ) ;
4148 const focus = ( ) => {
4249 vcCheckbox . value . focus ( ) ;
4350 } ;
@@ -58,8 +65,8 @@ export default defineComponent({
5865
5966 const onChange = ( e : RadioChangeEvent ) => {
6067 emit ( 'change' , e ) ;
61- if ( radioGroupContext && radioGroupContext . onRadioChange ) {
62- radioGroupContext . onRadioChange ( e ) ;
68+ if ( radioGroupContext && radioGroupContext . onChange ) {
69+ radioGroupContext . onChange ( e ) ;
6370 }
6471 } ;
6572
@@ -74,10 +81,10 @@ export default defineComponent({
7481 } ;
7582
7683 if ( radioGroup ) {
77- rProps . name = radioGroup . props . name ;
84+ rProps . name = radioGroup . name . value ;
7885 rProps . onChange = onChange ;
79- rProps . checked = props . value === radioGroup . stateValue . value ;
80- rProps . disabled = props . disabled || radioGroup . props . disabled ;
86+ rProps . checked = props . value === radioGroup . value . value ;
87+ rProps . disabled = props . disabled || radioGroup . disabled . value ;
8188 } else {
8289 rProps . onChange = handleChange ;
8390 }
@@ -86,6 +93,7 @@ export default defineComponent({
8693 [ `${ prefixCls . value } -wrapper-checked` ] : rProps . checked ,
8794 [ `${ prefixCls . value } -wrapper-disabled` ] : rProps . disabled ,
8895 [ `${ prefixCls . value } -wrapper-rtl` ] : direction . value === 'rtl' ,
96+ [ `${ prefixCls . value } -wrapper-in-form-item` ] : formItemInputContext . isFormItemInput ,
8997 } ) ;
9098
9199 return (
0 commit comments