From 6a1706ba78c41f24261350d272ce62d8a4241df3 Mon Sep 17 00:00:00 2001 From: Brad Beattie Date: Thu, 19 Oct 2023 10:22:34 -0700 Subject: [PATCH] Update SearchFields.tsx --- src/components/search/SearchFields.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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));