From 2da46ebc7a068fb5aa6fe65f9f48a18ab74f994a Mon Sep 17 00:00:00 2001 From: grafixeyehero <32230989+grafixeyehero@users.noreply.github.com> Date: Sat, 1 Jun 2024 18:42:01 -0400 Subject: [PATCH] Backport pull request #5610 from jellyfin-web/release-10.9.z Fix Search Field for Tv Mode Original-merge: 003bc94e024a6c84190ab7f4cd5bb8d0ba22ff9d Merged-by: thornbill Backported-by: Joshua M. Boniface --- src/components/search/SearchFields.tsx | 12 ++-- src/elements/emby-input/Input.tsx | 84 +++++++++++++------------- 2 files changed, 49 insertions(+), 47 deletions(-) diff --git a/src/components/search/SearchFields.tsx b/src/components/search/SearchFields.tsx index 16b71d3d1e..d2be6c26b3 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 Input = forwardRef( + ({ id, label, className, onBlur, onFocus, ...props }, ref) => { + const [isFocused, setIsFocused] = useState(false); - const onBlurInternal = useCallback(e => { - setIsFocused(false); - onBlur?.(e); - }, [ onBlur ]); + const onBlurInternal = useCallback( + (e) => { + setIsFocused(false); + onBlur?.(e); + }, + [onBlur] + ); - const onFocusInternal = useCallback(e => { - setIsFocused(true); - onFocus?.(e); - }, [ onFocus ]); + const onFocusInternal = useCallback( + (e) => { + setIsFocused(true); + onFocus?.(e); + }, + [onFocus] + ); - return ( - <> - + + + ); + } +); + +Input.displayName = 'Input'; export default Input;