@@ -16,6 +16,7 @@ import { trans } from "i18n";
16
16
import { RefControl } from "comps/controls/refControl" ;
17
17
import { refMethods } from "comps/generators/withMethodExposing" ;
18
18
import { blurMethod , clickMethod , focusWithOptions } from "comps/utils/methodUtils" ;
19
+ import { fixOldInputCompData } from "./textInputComp/textInputConstants" ;
19
20
20
21
import { useContext , useEffect } from "react" ;
21
22
import { EditorContext } from "comps/editorState" ;
@@ -88,6 +89,7 @@ function fixOldData(oldData: any) {
88
89
*/
89
90
let SwitchTmpComp = ( function ( ) {
90
91
const childrenMap = {
92
+ defaultValue : booleanExposingStateControl ( "defaultValue" ) ,
91
93
value : booleanExposingStateControl ( "value" ) ,
92
94
label : LabelControl ,
93
95
onEvent : eventHandlerControl ( EventOptions ) ,
@@ -105,6 +107,13 @@ let SwitchTmpComp = (function () {
105
107
...formDataChildren ,
106
108
} ;
107
109
return new UICompBuilder ( childrenMap , ( props ) => {
110
+ const defaultValue = { ...props . defaultValue } . value ;
111
+ const value = { ...props . value } . value ;
112
+
113
+ useEffect ( ( ) => {
114
+ props . value . onChange ( defaultValue ) ;
115
+ } , [ defaultValue ] ) ;
116
+
108
117
return props . label ( {
109
118
style : props . style ,
110
119
labelStyle : props . labelStyle ,
@@ -113,7 +122,7 @@ let SwitchTmpComp = (function () {
113
122
children : (
114
123
< SwitchWrapper disabled = { props . disabled } $style = { props . inputFieldStyle } >
115
124
< Switch
116
- checked = { props . value . value }
125
+ checked = { value }
117
126
disabled = { props . disabled }
118
127
ref = { props . viewRef }
119
128
onChange = { ( checked ) => {
@@ -130,7 +139,7 @@ let SwitchTmpComp = (function () {
130
139
return (
131
140
< >
132
141
< Section name = { sectionNames . basic } >
133
- { children . value . propertyView ( { label : trans ( "switchComp.defaultValue" ) } ) }
142
+ { children . defaultValue . propertyView ( { label : trans ( "switchComp.defaultValue" ) } ) }
134
143
</ Section >
135
144
136
145
< FormDataPropertyView { ...children } />
@@ -170,6 +179,8 @@ let SwitchTmpComp = (function () {
170
179
. build ( ) ;
171
180
} ) ( ) ;
172
181
182
+ SwitchTmpComp = migrateOldData ( SwitchTmpComp , fixOldInputCompData ) ;
183
+
173
184
export const SwitchComp = withExposingConfigs ( SwitchTmpComp , [
174
185
new NameConfig ( "value" , trans ( "switchComp.valueDesc" ) ) ,
175
186
...CommonNameConfig ,
0 commit comments