1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Update SearchFields.tsx

This commit is contained in:
Brad Beattie 2023-10-19 10:22:34 -07:00 committed by Bill Thornton
parent 9cccbae5bb
commit 6a1706ba78

View file

@ -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<SearchFieldsProps> = ({ onSearch = () => {} }: SearchFieldsProps) => {
const SearchFields: FunctionComponent<SearchFieldsProps> = ({ onSearch = () => {}, query }: SearchFieldsProps) => {
const element = useRef<HTMLDivElement>(null);
const getSearchInput = () => element?.current?.querySelector<HTMLInputElement>('.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));