Skip to content

Commit

Permalink
feat(a11y): add hotkeys to search input aria props (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvandercar-vt authored Nov 27, 2024
1 parent db90438 commit fafef98
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/client/theme/SearchBar/SearchButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,20 @@ export const SearchButton = React.forwardRef<
return null;
}, []);

const [actionKeyAltText, actionKeyChild] =
key === ACTION_KEY_DEFAULT
? // eslint-disable-next-line react/jsx-key -- false flag
(['Control', <ControlKeyIcon />] as const)
: (['Meta', key] as const);

const shortcut = `${actionKeyAltText}+k`

return (
<button
type="button"
className="DocSearch DocSearch-Button"
aria-label={buttonAriaLabel}
aria-label={`${buttonAriaLabel} (${shortcut})`}
aria-keyshortcuts={shortcut}
{...props}
ref={ref}
>
Expand All @@ -84,9 +93,7 @@ export const SearchButton = React.forwardRef<
<span className="DocSearch-Button-Keys">
{key !== null && (
<>
<span className="DocSearch-Button-Key">
{key === ACTION_KEY_DEFAULT ? <ControlKeyIcon /> : key}
</span>
<span className="DocSearch-Button-Key">{actionKeyChild}</span>
<span className="DocSearch-Button-Key">K</span>
</>
)}
Expand Down

0 comments on commit fafef98

Please sign in to comment.