Skip to content

Commit

Permalink
fix: support Chrome autofill when event.key is undefined (#1888)
Browse files Browse the repository at this point in the history
* fix: event.key is undefined #1887

* Update packages/docsearch-react/src/useDocSearchKeyboardEvents.ts

Co-authored-by: François Chalifour <[email protected]>

---------

Co-authored-by: François Chalifour <[email protected]>
  • Loading branch information
非凡少年 and francoischalifour authored May 17, 2023
1 parent bae117c commit 3f15fdb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ dist/

# IDE
.vscode/
.idea

# Environment files
.env

# Cypress Video and Screenshots output
cypress/screenshots/
cypress/videos/
cypress/videos/
6 changes: 5 additions & 1 deletion packages/docsearch-react/src/useDocSearchKeyboardEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ export function useDocSearchKeyboardEvents({
if (
(event.keyCode === 27 && isOpen) ||
// The `Cmd+K` shortcut both opens and closes the modal.
(event.key.toLowerCase() === 'k' && (event.metaKey || event.ctrlKey)) ||
// We need to check for `event.key` because it can be `undefined` with
// Chrome's autofill feature.
// See https://github.com/paperjs/paper.js/issues/1398
(event.key?.toLowerCase() === 'k' &&
(event.metaKey || event.ctrlKey)) ||
// The `/` shortcut opens but doesn't close the modal because it's
// a character.
(!isEditingContent(event) && event.key === '/' && !isOpen)
Expand Down

0 comments on commit 3f15fdb

Please sign in to comment.