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

Fix onAlphaPicked callback, the query (search term) is not updated Properly

This commit is contained in:
grafixeyehero 2024-05-26 20:04:16 +03:00
parent 61976b8101
commit a51d700eff
2 changed files with 50 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,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 {
onSearch(query + value);
onSearch(inputValue + value);
}
}, [ onSearch, query ]);
}, [onSearch]);
const onChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
onSearch(e.target.value);
@ -43,6 +47,7 @@ const SearchFields: FC<SearchFieldsProps> = ({
style={{ marginBottom: 0 }}
>
<Input
ref={inputRef}
id='searchTextInput'
className='searchfields-txtSearch'
type='text'