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

69 lines
2.4 KiB
TypeScript
Raw Normal View History

import React, { type ChangeEvent, type FC, useCallback, useRef } from 'react';
import AlphaPicker from '../alphaPicker/AlphaPickerComponent';
2024-02-13 01:09:08 -05:00
import Input from 'elements/emby-input/Input';
2024-08-14 13:31:34 -04:00
import globalize from '../../lib/globalize';
2024-02-13 01:09:08 -05:00
import layoutManager from '../layoutManager';
import browser from '../../scripts/browser';
import 'material-design-icons-iconfont';
import '../../styles/flexstyles.scss';
import './searchfields.scss';
2021-05-28 15:58:41 -04:00
2024-06-11 00:23:57 +03:00
interface SearchFieldsProps {
2023-10-19 10:22:34 -07:00
query: string,
2022-02-15 23:45:52 +03:00
onSearch?: (query: string) => void
2024-06-11 00:23:57 +03:00
}
2024-02-13 01:09:08 -05:00
const SearchFields: FC<SearchFieldsProps> = ({
onSearch = () => { /* no-op */ },
query
2024-06-11 00:23:57 +03:00
}) => {
const inputRef = useRef<HTMLInputElement>(null);
2022-12-16 16:02:11 -05:00
const onAlphaPicked = useCallback((e: Event) => {
2022-02-18 14:27:39 +03:00
const value = (e as CustomEvent).detail.value;
const inputValue = inputRef.current?.value || '';
if (value === 'backspace') {
onSearch(inputValue.length ? inputValue.substring(0, inputValue.length - 1) : '');
} else {
onSearch(inputValue + value);
2021-05-28 15:58:41 -04:00
}
}, [onSearch]);
2024-02-13 01:09:08 -05:00
const onChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
onSearch(e.target.value);
}, [ onSearch ]);
2021-05-28 15:58:41 -04:00
return (
2024-02-13 01:09:08 -05:00
<div className='padded-left padded-right searchFields'>
<div className='searchFieldsInner flex align-items-center justify-content-center'>
2022-02-24 20:15:24 +03:00
<span className='searchfields-icon material-icons search' aria-hidden='true' />
<div
className='inputContainer flex-grow'
style={{ marginBottom: 0 }}
2024-02-13 01:09:08 -05:00
>
<Input
ref={inputRef}
2024-02-13 01:09:08 -05:00
id='searchTextInput'
className='searchfields-txtSearch'
type='text'
data-keyboard='true'
placeholder={globalize.translate('Search')}
autoComplete='off'
maxLength={40}
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus
value={query}
onChange={onChange}
/>
</div>
</div>
2023-03-29 00:38:22 -04:00
{layoutManager.tv && !browser.tv
&& <AlphaPicker onAlphaPicked={onAlphaPicked} />
}
</div>
2021-05-28 15:58:41 -04:00
);
};
2021-06-01 15:19:02 -04:00
export default SearchFields;