diff options
author | Revanshu Paliwal <revanshu.paliwal@sonarsource.com> | 2024-01-31 17:55:06 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-02-01 20:02:47 +0000 |
commit | 59fa489912c52e548b0d80a12b57c34b3f7502ab (patch) | |
tree | 86d62063f67771141009a2788157d6e06ffc1ddd | |
parent | 42ca7ca0c80db4176252051a8684c597ae6d4d66 (diff) | |
download | sonarqube-59fa489912c52e548b0d80a12b57c34b3f7502ab.tar.gz sonarqube-59fa489912c52e548b0d80a12b57c34b3f7502ab.zip |
SONAR-21188 Fixing input search component for typing issue
-rw-r--r-- | server/sonar-web/design-system/src/components/input/InputSearch.tsx | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/server/sonar-web/design-system/src/components/input/InputSearch.tsx b/server/sonar-web/design-system/src/components/input/InputSearch.tsx index e3288bbc497..6880e047c49 100644 --- a/server/sonar-web/design-system/src/components/input/InputSearch.tsx +++ b/server/sonar-web/design-system/src/components/input/InputSearch.tsx @@ -78,12 +78,10 @@ export function InputSearch(props: PropsWithChildren<Props>) { const intl = useIntl(); const input = useRef<null | HTMLElement>(null); const [value, setValue] = useState(parentValue ?? ''); - const [dirty, setDirty] = useState(false); const debouncedOnChange = useMemo( () => debounce((val: string) => { onChange(val); - setDirty(false); }, DEBOUNCE_DELAY), [onChange], ); @@ -95,7 +93,9 @@ export function InputSearch(props: PropsWithChildren<Props>) { }); useEffect(() => { - if (parentValue !== undefined && !dirty) { + // initially letting parentValue control the value of the input + // later the value is controlled by the local value state + if (parentValue === '' || (parentValue !== undefined && value === '')) { setValue(parentValue); } }, [parentValue]); // eslint-disable-line @@ -115,7 +115,6 @@ export function InputSearch(props: PropsWithChildren<Props>) { const handleInputChange = (event: React.SyntheticEvent<HTMLInputElement>) => { const eventValue = event.currentTarget.value; setValue(eventValue); - setDirty(true); changeValue(eventValue); }; |