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:
parent
df6d96f5b6
commit
3d3e2eed8c
4 changed files with 45 additions and 19 deletions
|
@ -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('');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue