diff --git a/src/components/search/SearchFields.tsx b/src/components/search/SearchFields.tsx index cdc8c69a3c..70bbb8a76f 100644 --- a/src/components/search/SearchFields.tsx +++ b/src/components/search/SearchFields.tsx @@ -31,17 +31,23 @@ const createInputElement = () => ({ const normalizeInput = (value = '') => value.trim(); type SearchFieldsProps = { + query: string, onSearch?: (query: string) => void }; // eslint-disable-next-line @typescript-eslint/no-empty-function -const SearchFields: FunctionComponent = ({ onSearch = () => {} }: SearchFieldsProps) => { +const SearchFields: FunctionComponent = ({ onSearch = () => {}, query }: SearchFieldsProps) => { const element = useRef(null); const getSearchInput = () => element?.current?.querySelector('.searchfields-txtSearch'); const debouncedOnSearch = useMemo(() => debounce(onSearch, 400), [onSearch]); + const initSearchInput = getSearchInput(); + if (initSearchInput) { + initSearchInput.value = query; + } + useEffect(() => { getSearchInput()?.addEventListener('input', e => { debouncedOnSearch(normalizeInput((e.target as HTMLInputElement).value));