@@ -11,7 +11,7 @@ import { stringExposingStateControl } from "comps/controls/codeStateControl";
11
11
import { LabelControl } from "comps/controls/labelControl" ;
12
12
import { InputLikeStyleType , LabelStyleType , heightCalculator , widthCalculator } from "comps/controls/styleControlConstants" ;
13
13
import { Section , sectionNames , ValueFromOption } from "lowcoder-design" ;
14
- import { fromPairs } from "lodash" ;
14
+ import { debounce , fromPairs } from "lodash" ;
15
15
import { css } from "styled-components" ;
16
16
import { EMAIL_PATTERN , URL_PATTERN } from "util/stringUtils" ;
17
17
import { MultiBaseComp , RecordConstructorToComp , RecordConstructorToView } from "lowcoder-core" ;
@@ -33,7 +33,7 @@ import {
33
33
showDataLoadingIndicatorsPropertyView ,
34
34
} from "comps/utils/propertyUtils" ;
35
35
import { trans } from "i18n" ;
36
- import { ChangeEvent , useEffect , useRef , useState } from "react" ;
36
+ import { ChangeEvent , useEffect , useMemo , useRef , useState } from "react" ;
37
37
import { refMethods } from "comps/generators/withMethodExposing" ;
38
38
import { InputRef } from "antd/es/input" ;
39
39
import {
@@ -199,7 +199,6 @@ export const useTextInputProps = (props: RecordConstructorToView<typeof textInpu
199
199
} ,
200
200
} )
201
201
) ;
202
- propsRef . current . onEvent ( "change" ) ;
203
202
changeRef . current = false ;
204
203
} , [ localInputValue ] ) ;
205
204
@@ -216,19 +215,21 @@ export const useTextInputProps = (props: RecordConstructorToView<typeof textInpu
216
215
) ;
217
216
} , [ props . customRule ] )
218
217
219
- const onChangeRef = useRef (
220
- ( value : string ) => {
221
- props . value . onChange ( value ) ;
222
- }
218
+ const debouncedOnChangeRef = useRef (
219
+ debounce ( function ( value : string , valueCtx : any ) {
220
+ propsRef . current . value . onChange ( value ) ;
221
+ propsRef . current . onEvent ( "change" ) ;
222
+ } , 1000 )
223
223
) ;
224
+
224
225
225
226
const handleChange = ( e : ChangeEvent < HTMLInputElement > ) => {
226
227
const value = e . target . value ;
227
228
setLocalInputValue ( value ) ;
228
229
229
230
changeRef . current = true ;
230
231
touchRef . current = true ;
231
- onChangeRef . current ?.( value ) ;
232
+ debouncedOnChangeRef . current ?.( value , propsRef . current . value ) ;
232
233
} ;
233
234
234
235
// Cleanup refs on unmount
@@ -237,7 +238,7 @@ export const useTextInputProps = (props: RecordConstructorToView<typeof textInpu
237
238
changeRef . current = false ;
238
239
touchRef . current = false ;
239
240
propsRef . current = null as any ;
240
- onChangeRef . current = null as any ;
241
+ debouncedOnChangeRef . current . cancel ( ) ;
241
242
} ;
242
243
} , [ ] ) ;
243
244
0 commit comments