1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-26 06:19:36 +02:00

Fixed bug with weather logging. Fixed bug with search bar shortcuts

This commit is contained in:
Paweł Malak 2021-10-26 14:37:01 +02:00
parent df6d96f5b6
commit 3d3e2eed8c
4 changed files with 45 additions and 19 deletions

View file

@ -25,12 +25,28 @@ const SearchBar = (props: ComponentProps): JSX.Element => {
const inputRef = useRef<HTMLInputElement>(document.createElement('input'));
// Search bar autofocus
useEffect(() => {
if (!loading && !config.disableAutofocus) {
inputRef.current.focus();
}
}, [config]);
// Listen for keyboard events outside of search bar
useEffect(() => {
const keyOutsideFocus = (e: any) => {
const { key } = e as KeyboardEvent;
if (key === 'Escape') {
clearSearch();
}
};
window.addEventListener('keydown', keyOutsideFocus);
return () => window.removeEventListener('keydown', keyOutsideFocus);
}, []);
const clearSearch = () => {
inputRef.current.value = '';
setLocalSearch('');