diff --git a/src/components/search/SearchFields.tsx b/src/components/search/SearchFields.tsx index 16b71d3d1ed..d2be6c26b35 100644 --- a/src/components/search/SearchFields.tsx +++ b/src/components/search/SearchFields.tsx @@ -1,4 +1,4 @@ -import React, { type ChangeEvent, type FC, useCallback } from 'react'; +import React, { type ChangeEvent, type FC, useCallback, useRef } from 'react'; import AlphaPicker from '../alphaPicker/AlphaPickerComponent'; import Input from 'elements/emby-input/Input'; @@ -20,15 +20,18 @@ const SearchFields: FC = ({ onSearch = () => { /* no-op */ }, query }: SearchFieldsProps) => { + const inputRef = useRef(null); + const onAlphaPicked = useCallback((e: Event) => { const value = (e as CustomEvent).detail.value; + const inputValue = inputRef.current?.value || ''; if (value === 'backspace') { - onSearch(query.length ? query.substring(0, query.length - 1) : ''); + onSearch(inputValue.length ? inputValue.substring(0, inputValue.length - 1) : ''); } else { - onSearch(query + value); + onSearch(inputValue + value); } - }, [ onSearch, query ]); + }, [onSearch]); const onChange = useCallback((e: ChangeEvent) => { onSearch(e.target.value); @@ -43,6 +46,7 @@ const SearchFields: FC = ({ style={{ marginBottom: 0 }} > = ({ - id, - label, - className, - onBlur, - onFocus, - ...props -}) => { - const [ isFocused, setIsFocused ] = useState(false); - - const onBlurInternal = useCallback(e => { - setIsFocused(false); - onBlur?.(e); - }, [ onBlur ]); - - const onFocusInternal = useCallback(e => { - setIsFocused(true); - onFocus?.(e); - }, [ onFocus ]); - - return ( - <> - + + + ); + } +); + +Input.displayName = 'Input'; export default Input;