1- import type { ExtractPropTypes , PropType } from 'vue' ;
1+ import type { ExtractPropTypes } from 'vue' ;
22import { computed , defineComponent , ref } from 'vue' ;
33import PropTypes from '../_util/vue-types' ;
44import VcCheckbox from '../vc-checkbox/Checkbox' ;
@@ -9,31 +9,36 @@ import { FormItemInputContext, useInjectFormItemContext } from '../form/FormItem
99import omit from '../_util/omit' ;
1010import type { FocusEventHandler , MouseEventHandler } from '../_util/EventInterface' ;
1111import { useInjectRadioGroupContext , useInjectRadioOptionTypeContext } from './context' ;
12+ import { booleanType , functionType } from '../_util/type' ;
13+
14+ // CSSINJS
15+ import useStyle from './style' ;
1216
1317export const radioProps = ( ) => ( {
1418 prefixCls : String ,
15- checked : { type : Boolean , default : undefined } ,
16- disabled : { type : Boolean , default : undefined } ,
17- isGroup : { type : Boolean , default : undefined } ,
19+ checked : booleanType ( ) ,
20+ disabled : booleanType ( ) ,
21+ isGroup : booleanType ( ) ,
1822 value : PropTypes . any ,
1923 name : String ,
2024 id : String ,
21- autofocus : { type : Boolean , default : undefined } ,
22- onChange : Function as PropType < ( event : RadioChangeEvent ) => void > ,
23- onFocus : Function as PropType < FocusEventHandler > ,
24- onBlur : Function as PropType < FocusEventHandler > ,
25- onClick : Function as PropType < MouseEventHandler > ,
26- 'onUpdate:checked' : Function as PropType < ( checked : boolean ) => void > ,
27- 'onUpdate:value' : Function as PropType < ( checked : boolean ) => void > ,
25+ autofocus : booleanType ( ) ,
26+ onChange : functionType < ( event : RadioChangeEvent ) => void > ( ) ,
27+ onFocus : functionType < FocusEventHandler > ( ) ,
28+ onBlur : functionType < FocusEventHandler > ( ) ,
29+ onClick : functionType < MouseEventHandler > ( ) ,
30+ 'onUpdate:checked' : functionType < ( checked : boolean ) => void > ( ) ,
31+ 'onUpdate:value' : functionType < ( checked : boolean ) => void > ( ) ,
2832} ) ;
2933
3034export type RadioProps = Partial < ExtractPropTypes < ReturnType < typeof radioProps > > > ;
3135
3236export default defineComponent ( {
3337 compatConfig : { MODE : 3 } ,
3438 name : 'ARadio' ,
39+ inheritAttrs : false ,
3540 props : radioProps ( ) ,
36- setup ( props , { emit, expose, slots } ) {
41+ setup ( props , { emit, expose, slots, attrs } ) {
3742 const formItemContext = useInjectFormItemContext ( ) ;
3843 const formItemInputContext = FormItemInputContext . useInject ( ) ;
3944 const radioOptionTypeContext = useInjectRadioOptionTypeContext ( ) ;
@@ -42,10 +47,14 @@ export default defineComponent({
4247
4348 const { prefixCls : radioPrefixCls , direction } = useConfigInject ( 'radio' , props ) ;
4449 const prefixCls = computed ( ( ) =>
45- ( radioGroupContext ?. optionType . value || radioOptionTypeContext ) === 'button'
50+ radioGroupContext ?. optionType . value === 'button' || radioOptionTypeContext === 'button'
4651 ? `${ radioPrefixCls . value } -button`
4752 : radioPrefixCls . value ,
4853 ) ;
54+
55+ // Style
56+ const [ wrapSSR , hashId ] = useStyle ( radioPrefixCls ) ;
57+
4958 const focus = ( ) => {
5059 vcCheckbox . value . focus ( ) ;
5160 } ;
@@ -89,19 +98,23 @@ export default defineComponent({
8998 } else {
9099 rProps . onChange = handleChange ;
91100 }
92- const wrapperClassString = classNames ( {
93- [ `${ prefixCls . value } -wrapper` ] : true ,
94- [ `${ prefixCls . value } -wrapper-checked` ] : rProps . checked ,
95- [ `${ prefixCls . value } -wrapper-disabled` ] : rProps . disabled ,
96- [ `${ prefixCls . value } -wrapper-rtl` ] : direction . value === 'rtl' ,
97- [ `${ prefixCls . value } -wrapper-in-form-item` ] : formItemInputContext . isFormItemInput ,
98- } ) ;
101+ const wrapperClassString = classNames (
102+ {
103+ [ `${ prefixCls . value } -wrapper` ] : true ,
104+ [ `${ prefixCls . value } -wrapper-checked` ] : rProps . checked ,
105+ [ `${ prefixCls . value } -wrapper-disabled` ] : rProps . disabled ,
106+ [ `${ prefixCls . value } -wrapper-rtl` ] : direction . value === 'rtl' ,
107+ [ `${ prefixCls . value } -wrapper-in-form-item` ] : formItemInputContext . isFormItemInput ,
108+ } ,
109+ attrs . class ,
110+ hashId . value ,
111+ ) ;
99112
100- return (
101- < label class = { wrapperClassString } >
113+ return wrapSSR (
114+ < label { ... attrs } class = { wrapperClassString } >
102115 < VcCheckbox { ...rProps } type = "radio" ref = { vcCheckbox } />
103116 { slots . default && < span > { slots . default ( ) } </ span > }
104- </ label >
117+ </ label > ,
105118 ) ;
106119 } ;
107120 } ,
0 commit comments