@@ -11,7 +11,7 @@ import useConfigInject from '../config-provider/hooks/useConfigInject';
1111import { useInjectFormItemContext } from '../form/FormItemContext' ;
1212import omit from '../_util/omit' ;
1313import type { FocusEventHandler } from '../_util/EventInterface' ;
14-
14+ import useStyle from './style' ;
1515export const SwitchSizes = tuple ( 'small' , 'default' ) ;
1616type CheckedType = boolean | string | number ;
1717export const switchProps = ( ) => ( {
@@ -89,6 +89,7 @@ const Switch = defineComponent({
8989 ) ;
9090
9191 const { prefixCls, direction, size } = useConfigInject ( 'switch' , props ) ;
92+ const [ wrapSSR , hashId ] = useStyle ( prefixCls ) ;
9293 const refSwitchNode = ref ( ) ;
9394 const focus = ( ) => {
9495 refSwitchNode . value ?. focus ( ) ;
@@ -148,47 +149,52 @@ const Switch = defineComponent({
148149 [ `${ prefixCls . value } -disabled` ] : props . disabled ,
149150 [ prefixCls . value ] : true ,
150151 [ `${ prefixCls . value } -rtl` ] : direction . value === 'rtl' ,
152+ [ hashId . value ] : true ,
151153 } ) ) ;
152154
153- return ( ) => (
154- < Wave insertExtraNode >
155- < button
156- { ...omit ( props , [
157- 'prefixCls' ,
158- 'checkedChildren' ,
159- 'unCheckedChildren' ,
160- 'checked' ,
161- 'autofocus' ,
162- 'checkedValue' ,
163- 'unCheckedValue' ,
164- 'id' ,
165- 'onChange' ,
166- 'onUpdate:checked' ,
167- ] ) }
168- { ...attrs }
169- id = { props . id ?? formItemContext . id . value }
170- onKeydown = { handleKeyDown }
171- onClick = { handleClick }
172- onBlur = { handleBlur }
173- onMouseup = { handleMouseUp }
174- type = "button"
175- role = "switch"
176- aria-checked = { checked . value as any }
177- disabled = { props . disabled || props . loading }
178- class = { [ attrs . class , classNames . value ] }
179- ref = { refSwitchNode }
180- >
181- < div class = { `${ prefixCls . value } -handle` } >
182- { props . loading ? < LoadingOutlined class = { `${ prefixCls . value } -loading-icon` } /> : null }
183- </ div >
184- < span class = { `${ prefixCls . value } -inner` } >
185- { checkedStatus . value
186- ? getPropsSlot ( slots , props , 'checkedChildren' )
187- : getPropsSlot ( slots , props , 'unCheckedChildren' ) }
188- </ span >
189- </ button >
190- </ Wave >
191- ) ;
155+ return ( ) =>
156+ wrapSSR (
157+ < Wave insertExtraNode >
158+ < button
159+ { ...omit ( props , [
160+ 'prefixCls' ,
161+ 'checkedChildren' ,
162+ 'unCheckedChildren' ,
163+ 'checked' ,
164+ 'autofocus' ,
165+ 'checkedValue' ,
166+ 'unCheckedValue' ,
167+ 'id' ,
168+ 'onChange' ,
169+ 'onUpdate:checked' ,
170+ ] ) }
171+ { ...attrs }
172+ id = { props . id ?? formItemContext . id . value }
173+ onKeydown = { handleKeyDown }
174+ onClick = { handleClick }
175+ onBlur = { handleBlur }
176+ onMouseup = { handleMouseUp }
177+ type = "button"
178+ role = "switch"
179+ aria-checked = { checked . value as any }
180+ disabled = { props . disabled || props . loading }
181+ class = { [ attrs . class , classNames . value ] }
182+ ref = { refSwitchNode }
183+ >
184+ < div class = { `${ prefixCls . value } -handle` } >
185+ { props . loading ? < LoadingOutlined class = { `${ prefixCls . value } -loading-icon` } /> : null }
186+ </ div >
187+ < span class = { `${ prefixCls . value } -inner` } >
188+ < span class = { `${ prefixCls . value } -inner-checked` } >
189+ { getPropsSlot ( slots , props , 'checkedChildren' ) }
190+ </ span >
191+ < span class = { `${ prefixCls . value } -inner-unchecked` } >
192+ { getPropsSlot ( slots , props , 'unCheckedChildren' ) }
193+ </ span >
194+ </ span >
195+ </ button >
196+ </ Wave > ,
197+ ) ;
192198 } ,
193199} ) ;
194200
0 commit comments