mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Backport pull request #5610 from jellyfin-web/release-10.9.z
Fix Search Field for Tv Mode
Original-merge: 003bc94e02
Merged-by: thornbill <thornbill@users.noreply.github.com>
Backported-by: Joshua M. Boniface <joshua@boniface.me>
This commit is contained in:
parent
406a20334e
commit
2da46ebc7a
2 changed files with 49 additions and 47 deletions
|
@ -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 AlphaPicker from '../alphaPicker/AlphaPickerComponent';
|
||||||
import Input from 'elements/emby-input/Input';
|
import Input from 'elements/emby-input/Input';
|
||||||
|
@ -20,15 +20,18 @@ const SearchFields: FC<SearchFieldsProps> = ({
|
||||||
onSearch = () => { /* no-op */ },
|
onSearch = () => { /* no-op */ },
|
||||||
query
|
query
|
||||||
}: SearchFieldsProps) => {
|
}: SearchFieldsProps) => {
|
||||||
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const onAlphaPicked = useCallback((e: Event) => {
|
const onAlphaPicked = useCallback((e: Event) => {
|
||||||
const value = (e as CustomEvent).detail.value;
|
const value = (e as CustomEvent).detail.value;
|
||||||
|
const inputValue = inputRef.current?.value || '';
|
||||||
|
|
||||||
if (value === 'backspace') {
|
if (value === 'backspace') {
|
||||||
onSearch(query.length ? query.substring(0, query.length - 1) : '');
|
onSearch(inputValue.length ? inputValue.substring(0, inputValue.length - 1) : '');
|
||||||
} else {
|
} else {
|
||||||
onSearch(query + value);
|
onSearch(inputValue + value);
|
||||||
}
|
}
|
||||||
}, [ onSearch, query ]);
|
}, [onSearch]);
|
||||||
|
|
||||||
const onChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
|
const onChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
|
||||||
onSearch(e.target.value);
|
onSearch(e.target.value);
|
||||||
|
@ -43,6 +46,7 @@ const SearchFields: FC<SearchFieldsProps> = ({
|
||||||
style={{ marginBottom: 0 }}
|
style={{ marginBottom: 0 }}
|
||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
|
ref={inputRef}
|
||||||
id='searchTextInput'
|
id='searchTextInput'
|
||||||
className='searchfields-txtSearch'
|
className='searchfields-txtSearch'
|
||||||
type='text'
|
type='text'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import classNames from 'classnames';
|
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';
|
import './emby-input.scss';
|
||||||
|
|
||||||
|
@ -8,52 +8,50 @@ interface InputProps extends DetailedHTMLProps<InputHTMLAttributes<HTMLInputElem
|
||||||
label?: string
|
label?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const Input: FC<InputProps> = ({
|
const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||||
id,
|
({ id, label, className, onBlur, onFocus, ...props }, ref) => {
|
||||||
label,
|
|
||||||
className,
|
|
||||||
onBlur,
|
|
||||||
onFocus,
|
|
||||||
...props
|
|
||||||
}) => {
|
|
||||||
const [isFocused, setIsFocused] = useState(false);
|
const [isFocused, setIsFocused] = useState(false);
|
||||||
|
|
||||||
const onBlurInternal = useCallback(e => {
|
const onBlurInternal = useCallback(
|
||||||
|
(e) => {
|
||||||
setIsFocused(false);
|
setIsFocused(false);
|
||||||
onBlur?.(e);
|
onBlur?.(e);
|
||||||
}, [ onBlur ]);
|
},
|
||||||
|
[onBlur]
|
||||||
|
);
|
||||||
|
|
||||||
const onFocusInternal = useCallback(e => {
|
const onFocusInternal = useCallback(
|
||||||
|
(e) => {
|
||||||
setIsFocused(true);
|
setIsFocused(true);
|
||||||
onFocus?.(e);
|
onFocus?.(e);
|
||||||
}, [ onFocus ]);
|
},
|
||||||
|
[onFocus]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<label
|
<label
|
||||||
htmlFor={id}
|
htmlFor={id}
|
||||||
className={classNames(
|
className={classNames('inputLabel', {
|
||||||
'inputLabel',
|
|
||||||
{
|
|
||||||
inputLabelUnfocused: !isFocused,
|
inputLabelUnfocused: !isFocused,
|
||||||
inputLabelFocused: isFocused
|
inputLabelFocused: isFocused
|
||||||
}
|
})}
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
|
ref={ref}
|
||||||
id={id}
|
id={id}
|
||||||
className={classNames(
|
className={classNames('emby-input', className)}
|
||||||
'emby-input',
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
onBlur={onBlurInternal}
|
onBlur={onBlurInternal}
|
||||||
onFocus={onFocusInternal}
|
onFocus={onFocusInternal}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Input.displayName = 'Input';
|
||||||
|
|
||||||
export default Input;
|
export default Input;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue