feat(a11y): add aria-keyshortcuts to search button (#2365)
This commit is contained in:
parent
b21e3c6c14
commit
b68a79261e
2 changed files with 7 additions and 4 deletions
|
|
@ -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}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -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 () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue