Skip to content

fix(core): prevent search button from intercepting browser shortcuts when focused#2871

Open
Sigmabrogz wants to merge 1 commit intoalgolia:mainfrom
Sigmabrogz:fix/search-button-keyboard-shortcuts
Open

fix(core): prevent search button from intercepting browser shortcuts when focused#2871
Sigmabrogz wants to merge 1 commit intoalgolia:mainfrom
Sigmabrogz:fix/search-button-keyboard-shortcuts

Conversation

@Sigmabrogz
Copy link
Copy Markdown

Summary

Fixes an issue where focusing the DocSearchButton and pressing keyboard shortcuts (like Cmd+Opt+I to open DevTools, or Cmd+R to reload) would be intercepted as a search query, opening the modal and prepopulating the search input with a modifier key name (like Dead, r, etc).

Problem

Fixes #2855.
useDocSearchKeyboardEvents listens for key presses globally via window.addEventListener('keydown'). It has a helper isEditingContent which skips interception if the user is currently focused on an INPUT, TEXTAREA, SELECT, or a contentEditable element. However, it did not include BUTTON.

When the DocSearch button is focused, typing ANY character is currently captured as the initialQuery (which is by design so you can just start typing). Unfortunately, this was also capturing chords containing modifier keys (Command/Control/Alt).

Solution

Updated the isEditingContent helper to also return true if the tagName is BUTTON. This ensures that standard browser shortcuts (which require the keydown event to propagate natively) are not swallowed when the search button happens to be the active element.

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 15, 2026

👷 Deploy request for docsearch pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 0e2b7c0

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 15, 2026

Deploy Preview for docsearch-demo failed.

Name Link
🔨 Latest commit 0e2b7c0
🔍 Latest deploy log https://app.netlify.com/projects/docsearch-demo/deploys/69b7096f4b2ff70008adc3eb

@Sigmabrogz
Copy link
Copy Markdown
Author

This addresses the issue with the search button swallowing browser shortcuts when focused (like DevTools and page reload).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search button intercepts browser shortcuts when focused

1 participant