1
0
Fork 0

feat(a11y): add aria-keyshortcuts to search button (#2365)

This commit is contained in:
Blake V. 2025-04-18 00:31:24 -06:00 committed by GitHub
parent b21e3c6c14
commit b68a79261e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View file

@ -34,14 +34,17 @@ export const DocSearchButton = React.forwardRef<HTMLButtonElement, DocSearchButt
const [actionKeyReactsTo, actionKeyAltText, actionKeyChild] =
key === ACTION_KEY_DEFAULT
? // eslint-disable-next-line react/jsx-key -- false flag
([ACTION_KEY_DEFAULT, 'Ctrl', <ControlKeyIcon />] as const)
: (['Meta', 'Command', key] as const);
([ACTION_KEY_DEFAULT, 'Control', <ControlKeyIcon />] as const)
: (['Meta', 'Meta', key] as const);
const shortcut = `${actionKeyAltText}+k`;
return (
<button
type="button"
className="DocSearch DocSearch-Button"
aria-label={`${buttonAriaLabel} (${actionKeyAltText}+K)`}
aria-label={`${buttonAriaLabel} (${shortcut})`}
aria-keyshortcuts={shortcut}
{...props}
ref={ref}
>

View file

@ -59,7 +59,7 @@ describe('api', () => {
);
expect(document.querySelector(docSearchSelector)).toBeInTheDocument();
expect(document.querySelector('.DocSearch-Button-Placeholder')?.innerHTML).toBe('Recherche');
expect(document.querySelector('.DocSearch-Button')?.getAttribute('aria-label')).toBe('Recherche (Ctrl+K)');
expect(document.querySelector('.DocSearch-Button')?.getAttribute('aria-label')).toBe('Recherche (Control+k)');
});
it('overrides the default DocSearchModal startScreen text', async () => {