]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21188 Fixing input search component for typing issue
authorRevanshu Paliwal <revanshu.paliwal@sonarsource.com>
Wed, 31 Jan 2024 16:55:06 +0000 (17:55 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 1 Feb 2024 20:02:47 +0000 (20:02 +0000)
server/sonar-web/design-system/src/components/input/InputSearch.tsx

index e3288bbc497c498656f63fa6f6300c1c1ceb8ea9..6880e047c49745b1de1ffa679a58bdb65ae2a09d 100644 (file)
@@ -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);
   };