Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita04a57b

Browse files
fix autocomplete input glitch
1 parent5987158 commita04a57b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

‎client/packages/lowcoder/src/comps/comps/autoCompleteComp/autoCompleteComp.tsx‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{ReactNode,useEffect,useState,useCallback}from"react";
1+
import{ReactNode,useEffect,useState,useCallback,useRef}from"react";
22
import{Input,Section,sectionNames}from"lowcoder-design";
33
import{BoolControl}from"comps/controls/boolControl";
44
import{styleControl}from"comps/controls/styleControl";
@@ -148,12 +148,19 @@ let AutoCompleteCompBase = (function () {
148148
const[activationFlag,setActivationFlag]=useState(false);
149149
const[searchtext,setsearchtext]=useState<string>(props.value.value);
150150
const[validateState,setvalidateState]=useState({});
151+
152+
// Use simple refs like text input components
153+
constchangeRef=useRef(false);
154+
consttouchRef=useRef(false);
151155

152156
// 是否中文环境
153157
const[chineseEnv,setChineseEnv]=useState(getDayJSLocale()==="zh-cn");
154158

155159
useEffect(()=>{
156-
setsearchtext(props.value.value);
160+
// Only update local state from props if user hasn't touched the input
161+
if(!touchRef.current){
162+
setsearchtext(props.value.value);
163+
}
157164
activationFlag&&
158165
setvalidateState(textInputValidate(getTextInputValidate()));
159166
},[
@@ -247,19 +254,27 @@ let AutoCompleteCompBase = (function () {
247254
props.valueInItems.onChange(false);
248255
setvalidateState(textInputValidate(getTextInputValidate()));
249256
setsearchtext(value);
257+
changeRef.current=true;
258+
touchRef.current=true;
259+
260+
// Update parent value immediately to prevent sync issues
250261
props.value.onChange(value);
251262
props.onEvent("change");
263+
252264
if(!Boolean(value)){
253265
props.selectedOption.onChange({});
254266
}
255267
},[props.valueInItems,getTextInputValidate,props.value,props.onEvent,props.selectedOption]);
256268

257269
consthandleSelect=useCallback((data:string,option:any)=>{
258-
setsearchtext(option[valueOrLabel]);
270+
constselectedValue=option[valueOrLabel];
271+
setsearchtext(selectedValue);
259272
props.valueInItems.onChange(true);
260-
props.value.onChange(option[valueOrLabel]);
273+
props.value.onChange(selectedValue);
261274
props.selectedOption.onChange(option);
262275
props.onEvent("submit");
276+
changeRef.current=true;
277+
touchRef.current=true;
263278
},[valueOrLabel,props.valueInItems,props.value,props.onEvent,props.selectedOption]);
264279

265280
consthandleFocus=useCallback(()=>{
@@ -268,6 +283,7 @@ let AutoCompleteCompBase = (function () {
268283
},[props.onEvent]);
269284

270285
consthandleBlur=useCallback(()=>{
286+
touchRef.current=false;
271287
props.onEvent("blur");
272288
},[props.onEvent]);
273289

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp