Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Search Field for Tv Mode #5610

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/components/search/SearchFields.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -20,15 +20,19 @@ 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 {
grafixeyehero marked this conversation as resolved.
Show resolved Hide resolved
onSearch(query + value);
onSearch(inputValue + value);
}
}, [ onSearch, query ]);
}, [onSearch]);

const onChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
onSearch(e.target.value);
Expand All @@ -43,6 +47,7 @@ const SearchFields: FC<SearchFieldsProps> = ({
style={{ marginBottom: 0 }}
>
<Input
ref={inputRef}
id='searchTextInput'
className='searchfields-txtSearch'
type='text'
Expand Down
90 changes: 44 additions & 46 deletions src/elements/emby-input/Input.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -8,52 +8,50 @@ interface InputProps extends DetailedHTMLProps<InputHTMLAttributes<HTMLInputElem
label?: string
}

const Input: FC<InputProps> = ({
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 (
<>
<label
htmlFor={id}
className={classNames(
'inputLabel',
{
const Input = forwardRef<HTMLInputElement, InputProps>(
({ id, label, className, onBlur, onFocus, ...props }, ref) => {
const [isFocused, setIsFocused] = useState(false);

const onBlurInternal = useCallback(
(e) => {
setIsFocused(false);
onBlur?.(e);
},
[onBlur]
);

const onFocusInternal = useCallback(
(e) => {
setIsFocused(true);
onFocus?.(e);
},
[onFocus]
);

return (
<>
<label
htmlFor={id}
className={classNames('inputLabel', {
inputLabelUnfocused: !isFocused,
inputLabelFocused: isFocused
}
)}
>
{label}
</label>
<input
id={id}
className={classNames(
'emby-input',
className
)}
onBlur={onBlurInternal}
onFocus={onFocusInternal}
{...props}
/>
</>
);
};
})}
>
{label}
</label>
<input
ref={ref}
id={id}
className={classNames('emby-input', className)}
onBlur={onBlurInternal}
onFocus={onFocusInternal}
{...props}
/>
</>
);
}
);

Input.displayName = 'Input';

export default Input;
Loading