1
0
Fork 0

fix(v5): ignore slash shortcut on focused buttons (#2955)

Backport of #2871.\n\nOriginal commit: 0e41a78c44

Co-authored-by: Sigmabro <122412346+Sigmabrogz@users.noreply.github.com>
This commit is contained in:
Paul Jankowski 2026-08-05 12:15:42 -04:00 committed by GitHub
parent a8fecaaad6
commit 3f74c33d45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 37 additions and 2 deletions

View file

@ -0,0 +1,6 @@
---
"@docsearch/core": patch
"@docsearch/react": patch
---
Prevent the slash search shortcut from intercepting key events on focused buttons.

View file

@ -138,6 +138,21 @@ describe('@docsearch/core', () => {
expect(screen.getByText('State: modal-search')).toBeInTheDocument(); expect(screen.getByText('State: modal-search')).toBeInTheDocument();
}); });
it('does not open search with / from a focused button', () => {
renderWithProvider(
<>
<StateRender />
<button type="button">Action</button>
</>
);
const button = screen.getByRole('button', { name: 'Action' });
button.focus();
fireEvent.keyDown(button, { key: '/', code: 'Slash' });
expect(screen.getByText('State: ready')).toBeInTheDocument();
});
it('respects keyboard shortcuts', () => { it('respects keyboard shortcuts', () => {
renderWithProvider(<StateRender />, { renderWithProvider(<StateRender />, {
keyboardShortcuts: { keyboardShortcuts: {

View file

@ -34,7 +34,8 @@ function isEditingContent(event: KeyboardEvent): boolean {
element.isContentEditable || element.isContentEditable ||
tagName === 'INPUT' || tagName === 'INPUT' ||
tagName === 'SELECT' || tagName === 'SELECT' ||
tagName === 'TEXTAREA' tagName === 'TEXTAREA' ||
tagName === 'BUTTON'
); );
} }

View file

@ -62,6 +62,18 @@ describe('keyboard shortcuts', () => {
expect(document.querySelector('.DocSearch-Modal')).toBeInTheDocument(); expect(document.querySelector('.DocSearch-Modal')).toBeInTheDocument();
}); });
it('does not respond to / from the search button', () => {
render(<DocSearch />);
const button = screen.getByRole('button', { name: /Search/ });
button.focus();
fireEvent.keyDown(button, { key: '/', code: 'Slash' });
expect(
document.querySelector('.DocSearch-Modal')
).not.toBeInTheDocument();
});
}); });
describe('custom keyboard shortcuts configuration', () => { describe('custom keyboard shortcuts configuration', () => {

View file

@ -32,7 +32,8 @@ function isEditingContent(event: KeyboardEvent): boolean {
element.isContentEditable || element.isContentEditable ||
tagName === 'INPUT' || tagName === 'INPUT' ||
tagName === 'SELECT' || tagName === 'SELECT' ||
tagName === 'TEXTAREA' tagName === 'TEXTAREA' ||
tagName === 'BUTTON'
); );
} }