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

Merge pull request #5610 from grafixeyehero/Fix-Tv-Mode-search-field

Fix Search Field for Tv Mode
This commit is contained in:
Bill Thornton 2024-05-30 11:13:44 -04:00 committed by GitHub
commit 003bc94e02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 49 additions and 47 deletions

View file

@ -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<SearchFieldsProps> = ({
onSearch = () => { /* no-op */ },
query
}: SearchFieldsProps) => {
const inputRef = useRef<HTMLInputElement>(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<HTMLInputElement>) => {
onSearch(e.target.value);
@ -43,6 +46,7 @@ const SearchFields: FC<SearchFieldsProps> = ({
style={{ marginBottom: 0 }}
>
<Input
ref={inputRef}
id='searchTextInput'
className='searchfields-txtSearch'
type='text'

View file

@ -1,5 +1,5 @@
import classNames from 'classnames';
import React, { type DetailedHTMLProps, type InputHTMLAttributes, type FC, useState, useCallback } from 'react';
import React, { type DetailedHTMLProps, type InputHTMLAttributes, useState, useCallback, forwardRef } from 'react';
import './emby-input.scss';
@ -8,52 +8,50 @@ interface InputProps extends DetailedHTMLProps<InputHTMLAttributes<HTMLInputElem
label?: string
}
const Input: FC<InputProps> = ({
id,
label,
className,
onBlur,
onFocus,
...props
}) => {
const Input = forwardRef<HTMLInputElement, InputProps>(
({ id, label, className, onBlur, onFocus, ...props }, ref) => {
const [isFocused, setIsFocused] = useState(false);
const onBlurInternal = useCallback(e => {
const onBlurInternal = useCallback(
(e) => {
setIsFocused(false);
onBlur?.(e);
}, [ onBlur ]);
},
[onBlur]
);
const onFocusInternal = useCallback(e => {
const onFocusInternal = useCallback(
(e) => {
setIsFocused(true);
onFocus?.(e);
}, [ onFocus ]);
},
[onFocus]
);
return (
<>
<label
htmlFor={id}
className={classNames(
'inputLabel',
{
className={classNames('inputLabel', {
inputLabelUnfocused: !isFocused,
inputLabelFocused: isFocused
}
)}
})}
>
{label}
</label>
<input
ref={ref}
id={id}
className={classNames(
'emby-input',
className
)}
className={classNames('emby-input', className)}
onBlur={onBlurInternal}
onFocus={onFocusInternal}
{...props}
/>
</>
);
};
}
);
Input.displayName = 'Input';
export default Input;