Skip to content

Commit

Permalink
feat(docsearch): add / keyboard shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Jul 1, 2020
1 parent c13fa9f commit 5725023
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/useDocSearchKeyboardEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ export function useDocSearchKeyboardEvents({ isOpen, onOpen, onClose }) {
function onKeyDown(event: KeyboardEvent) {
if (
(event.keyCode === 27 && isOpen) ||
(event.key === 'k' && (event.metaKey || event.ctrlKey))
// The `Cmd+K` shortcut both opens and closes the modal.
(event.key === 'k' && (event.metaKey || event.ctrlKey)) ||
// The `/` shortcut opens but doesn't close the modal because it's
// a character.
(event.key === '/' && !isOpen)
) {
event.preventDefault();

Expand Down

0 comments on commit 5725023

Please sign in to comment.