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:
parent
9cccbae5bb
commit
6a1706ba78
1 changed files with 7 additions and 1 deletions
|
@ -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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue