Skip to content

Commit

Permalink
Merge pull request #44 from dheereshagrwal/power-shortcuts
Browse files Browse the repository at this point in the history
ctrl f or command f power shortcut
  • Loading branch information
dheereshagrwal authored Jan 14, 2025
2 parents b708cd9 + 45b19c1 commit 86af686
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ function SearchBox({ searchRef }: SearchProps) {
ref.current?.focus();
}
}, [focusTrigger]);

useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0;
if (
(isMac && event.metaKey && event.key === 'f') ||
(!isMac && event.ctrlKey && event.key === 'f')
) {
event.preventDefault();
ref.current?.focus();
}
};

window.addEventListener('keydown', handleKeyDown);

return () => {
window.removeEventListener('keydown', handleKeyDown);
};
});

const handleClearSearch = () => {
setSearch("");
ref.current?.focus();
Expand Down

0 comments on commit 86af686

Please sign in to comment.