Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

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 c970236 commit d3a7275
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/docsearch-react/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 d3a7275

Please sign in to comment.