Skip to content

Commit

Permalink
Fix: Prevent keypress from firing on inputs (#386)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
  • Loading branch information
huijing and delucis committed Jul 25, 2023
1 parent 30ce468 commit e6f6f30
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/quick-peas-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/starlight": patch
---

Prevent search keyboard shortcuts from triggering when input elements are focused
5 changes: 4 additions & 1 deletion packages/starlight/components/Search.astro
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,13 @@ const pagefindTranslations = {

// Listen for `/` and `cmd + k` keyboard shortcuts.
window.addEventListener('keydown', (e) => {
const isInput =
document.activeElement &&
['input', 'select', 'textarea'].includes(document.activeElement.tagName.toLowerCase());
if (e.metaKey === true && e.key === 'k') {
dialog.open ? closeModal() : openModal();
e.preventDefault();
} else if (e.key === '/' && !dialog.open) {
} else if (e.key === '/' && !dialog.open && !isInput) {
openModal();
e.preventDefault();
}
Expand Down

0 comments on commit e6f6f30

Please sign in to comment.