File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -70,4 +70,35 @@ describe('Switch', () => {
70
70
} ) ;
71
71
expect ( checked . value ) . toBe ( 1 ) ;
72
72
} ) ;
73
+
74
+ it ( 'customize checked value and children should work' , async ( ) => {
75
+ resetWarned ( ) ;
76
+ const checked = ref ( 1 ) ;
77
+ const onUpdate = val => ( checked . value = val ) ;
78
+ const wrapper = mount ( {
79
+ render ( ) {
80
+ return (
81
+ < Switch
82
+ { ...{ 'onUpdate:checked' : onUpdate } }
83
+ checked = { checked . value }
84
+ unCheckedValue = { 1 }
85
+ checkedValue = { 2 }
86
+ checkedChildren = "on"
87
+ unCheckedChildren = "off"
88
+ />
89
+ ) ;
90
+ } ,
91
+ } ) ;
92
+ await asyncExpect ( ( ) => {
93
+ wrapper . find ( 'button' ) . trigger ( 'click' ) ;
94
+ } ) ;
95
+ expect ( checked . value ) . toBe ( 2 ) ;
96
+ expect ( wrapper . find ( '.ant-switch-inner' ) . text ( ) ) . toBe ( 'on' ) ;
97
+
98
+ await asyncExpect ( ( ) => {
99
+ wrapper . find ( 'button' ) . trigger ( 'click' ) ;
100
+ } ) ;
101
+ expect ( checked . value ) . toBe ( 1 ) ;
102
+ expect ( wrapper . find ( '.ant-switch-inner' ) . text ( ) ) . toBe ( 'off' ) ;
103
+ } ) ;
73
104
} ) ;
Original file line number Diff line number Diff line change @@ -134,6 +134,7 @@ const Switch = defineComponent({
134
134
[ `${ prefixCls . value } -disabled` ] : props . disabled ,
135
135
[ prefixCls . value ] : true ,
136
136
} ) ) ;
137
+
137
138
return ( ) => (
138
139
< Wave insertExtraNode >
139
140
< button
@@ -160,7 +161,7 @@ const Switch = defineComponent({
160
161
>
161
162
{ props . loading ? < LoadingOutlined class = { `${ prefixCls . value } -loading-icon` } /> : null }
162
163
< span class = { `${ prefixCls . value } -inner` } >
163
- { checked . value
164
+ { checkedStatus . value
164
165
? getPropsSlot ( slots , props , 'checkedChildren' )
165
166
: getPropsSlot ( slots , props , 'unCheckedChildren' ) }
166
167
</ span >
You can’t perform that action at this time.
0 commit comments