File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ interface SwitchProps
2525 loadingIcon ?: React . ReactNode ;
2626 style ?: React . CSSProperties ;
2727 title ?: string ;
28+ styles ?: { content : React . CSSProperties } ;
29+ classNames ?: { content : string } ;
2830}
2931
3032const Switch = React . forwardRef < HTMLButtonElement , SwitchProps > (
@@ -41,6 +43,8 @@ const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>(
4143 onClick,
4244 onChange,
4345 onKeyDown,
46+ styles,
47+ classNames : switchClassNames ,
4448 ...restProps
4549 } ,
4650 ref ,
@@ -99,8 +103,18 @@ const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>(
99103 >
100104 { loadingIcon }
101105 < span className = { `${ prefixCls } -inner` } >
102- < span className = { `${ prefixCls } -inner-checked` } > { checkedChildren } </ span >
103- < span className = { `${ prefixCls } -inner-unchecked` } > { unCheckedChildren } </ span >
106+ < span
107+ className = { classNames ( `${ prefixCls } -inner-checked` , switchClassNames ?. content ) }
108+ style = { styles ?. content }
109+ >
110+ { checkedChildren }
111+ </ span >
112+ < span
113+ className = { classNames ( `${ prefixCls } -inner-unchecked` , switchClassNames ?. content ) }
114+ style = { styles ?. content }
115+ >
116+ { unCheckedChildren }
117+ </ span >
104118 </ span >
105119 </ button >
106120 ) ;
Original file line number Diff line number Diff line change @@ -129,4 +129,13 @@ describe('rc-switch', () => {
129129 wrapper . simulate ( 'click' ) ;
130130 expect ( onChange ) . not . toHaveBeenCalled ( ) ;
131131 } ) ;
132+ it ( 'support classnames and styles' , ( ) => {
133+ const wrapper = createSwitch ( {
134+ classNames : { content : 'custom-content' } ,
135+ styles : { content : { background : 'red' } } ,
136+ } ) ;
137+ const contentElement = wrapper . find ( '.custom-content' ) . at ( 0 ) ;
138+ expect ( contentElement . exists ( ) ) . toBe ( true ) ;
139+ expect ( contentElement . prop ( 'style' ) ) . toEqual ( { background : 'red' } ) ;
140+ } ) ;
132141} ) ;
You can’t perform that action at this time.
0 commit comments