From 5725023ae7afe9e9ebd1dab4641a1bdb3c986659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Wed, 1 Jul 2020 15:00:46 +0200 Subject: [PATCH] feat(docsearch): add `/` keyboard shortcut --- src/useDocSearchKeyboardEvents.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/useDocSearchKeyboardEvents.ts b/src/useDocSearchKeyboardEvents.ts index f869ba8a4..61c387724 100644 --- a/src/useDocSearchKeyboardEvents.ts +++ b/src/useDocSearchKeyboardEvents.ts @@ -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();