mirror of
https://github.com/pawelmalak/flame.git
synced 2026-03-07 04:53:12 +08:00
Fixed bug with weather logging. Fixed bug with search bar shortcuts
This commit is contained in:
@@ -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('');
|
||||
|
||||
Reference in New Issue
Block a user