1 import { c, msgid } from 'ttag';
3 const useAutocompleteAriaProps = ({ baseId, selectedSuggest }: { baseId: string; selectedSuggest?: number }) => {
4 const helpTextId = `${baseId}-help-text`;
6 <span id={helpTextId} className="sr-only">
8 .t`Use Up and Down keys to access and browse suggestions after input. Press Enter to confirm your choice, or Escape to close the suggestions box.`}
11 const getNumberHelpText = (numberOfSuggests: number) =>
12 numberOfSuggests > 0 ? (
13 <div className="sr-only" aria-atomic="true" aria-live="assertive">
15 msgid`Found ${numberOfSuggests} suggestion, use keyboard to navigate.`,
16 `Found ${numberOfSuggests} suggestions, use keyboard to navigate.`,
23 const suggestionsId = `${baseId}-suggestions`;
24 const getOptionId = (idx: number) => `${baseId}-option-${idx}`;
32 'aria-autocomplete': 'list' as const,
33 'aria-owns': suggestionsId,
34 'aria-activedescendant': selectedSuggest !== undefined ? getOptionId(selectedSuggest) : undefined,
35 'aria-describedby': helpTextId,
37 autoCapitalize: 'off',
41 suggestionsAriaProps: {
45 getAriaPropsForOption: (idx: number) => ({
54 export default useAutocompleteAriaProps;