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
25
25
loadingIcon ?: React . ReactNode ;
26
26
style ?: React . CSSProperties ;
27
27
title ?: string ;
28
+ styles ?: { content : React . CSSProperties } ;
29
+ classNames ?: { content : string } ;
28
30
}
29
31
30
32
const Switch = React . forwardRef < HTMLButtonElement , SwitchProps > (
@@ -41,6 +43,8 @@ const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>(
41
43
onClick,
42
44
onChange,
43
45
onKeyDown,
46
+ styles,
47
+ classNames : switchClassNames ,
44
48
...restProps
45
49
} ,
46
50
ref ,
@@ -99,8 +103,18 @@ const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>(
99
103
>
100
104
{ loadingIcon }
101
105
< 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 >
104
118
</ span >
105
119
</ button >
106
120
) ;
Original file line number Diff line number Diff line change @@ -129,4 +129,13 @@ describe('rc-switch', () => {
129
129
wrapper . simulate ( 'click' ) ;
130
130
expect ( onChange ) . not . toHaveBeenCalled ( ) ;
131
131
} ) ;
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
+ } ) ;
132
141
} ) ;
You can’t perform that action at this time.
0 commit comments