-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added accessibility folder, added helper fucntions for aria messages …
…for focusedValue, focusedOption and results context
- Loading branch information
1 parent
4da6217
commit b3697d1
Showing
4 changed files
with
68 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export type InstructionsContext = { isSearchable?: boolean, isMulti?: boolean, label?: string }; | ||
export type ValueEventContext = { value: string }; | ||
|
||
export const instructionsAriaMessage = (event, context?: InstructionsContext = {}) => { | ||
const { isSearchable, isMulti, label } = context; | ||
switch (event) { | ||
case 'menu': | ||
return 'Use Up and Down to choose options, press Backspace to select the currently focused option, press Escape to exit the menu, press Tab to select the option and exit the menu.'; | ||
case 'input': | ||
return `${label ? label : 'Select'} is focused ${ isSearchable ? ',type to refine list' : '' }, press Down to open the menu, ${ isMulti ? ' press left to focus selected values' : '' }`; | ||
case 'value': | ||
return 'Use left and right to toggle between focused values, press Enter to remove the currently focused value'; | ||
} | ||
}; | ||
|
||
export const valueEventAriaMessage = (event, context: ValueEventContext) => { | ||
const { value } = context; | ||
switch (event) { | ||
case 'deselect-option': | ||
case 'pop-value': | ||
case 'remove-value': | ||
return `option ${value}, deselected.`; | ||
case 'select-option': | ||
return `option ${value}, selected.`; | ||
} | ||
}; | ||
|
||
export const valueFocusAriaMessage = ({ focusedValue, getOptionLabel, selectValue }) => `value ${getOptionLabel(focusedValue)} focused, ${selectValue.indexOf(focusedValue) + 1} of ${selectValue.length}.`; | ||
export const optionFocusAriaMessage = ({ focusedOption, getOptionLabel, options }) => `option ${getOptionLabel(focusedOption)} focused, ${options.indexOf(focusedOption) + 1} of ${options.length}.`; | ||
export const resultsAriaMessage = ({ inputValue, screenReaderMessage }) => `${screenReaderMessage} for search term ${inputValue}.`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters