Skip to content

Commit

Permalink
Merge pull request #74 from infinitered/trevorcoleman/accessibility-role
Browse files Browse the repository at this point in the history
Update CONSTS to direct developers to use role instead of accessibilityRole (Expensify#31500)
  • Loading branch information
trevor-coleman authored Nov 20, 2023
2 parents ff4c947 + 0639e66 commit 2336f3b
Show file tree
Hide file tree
Showing 117 changed files with 296 additions and 171 deletions.
116 changes: 112 additions & 4 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2769,17 +2769,125 @@ const CONST = {
EXPENSIFY_LOGO_SIZE_RATIO: 0.22,
EXPENSIFY_LOGO_MARGIN_RATIO: 0.03,
},
/**
* Acceptable values for the `accessibilityRole` prop on react native components.
*
* **IMPORTANT:** Do not use with the `role` prop as it can cause errors.
*
* @deprecated ACCESSIBILITY_ROLE is deprecated. Please use CONST.ROLE instead.
*/
ACCESSIBILITY_ROLE: {
/**
* @deprecated Please stop using the accessibilityRole prop and use the role prop instead.
*/
BUTTON: 'button',

/**
* @deprecated Please stop using the accessibilityRole prop and use the role prop instead.
*/
LINK: 'link',

/**
* @deprecated Please stop using the accessibilityRole prop and use the role prop instead.
*/
MENUITEM: 'menuitem',
TEXT: 'presentation',

/**
* @deprecated Please stop using the accessibilityRole prop and use the role prop instead.
*/
TEXT: 'text',

/**
* @deprecated Please stop using the accessibilityRole prop and use the role prop instead.
*/
RADIO: 'radio',
IMAGEBUTTON: 'img button',

/**
* @deprecated Please stop using the accessibilityRole prop and use the role prop instead.
*/
IMAGEBUTTON: 'imagebutton',

/**
* @deprecated Please stop using the accessibilityRole prop and use the role prop instead.
*/
CHECKBOX: 'checkbox',

/**
* @deprecated Please stop using the accessibilityRole prop and use the role prop instead.
*/
SWITCH: 'switch',

/**
* @deprecated Please stop using the accessibilityRole prop and use the role prop instead.
*/
ADJUSTABLE: 'adjustable',

/**
* @deprecated Please stop using the accessibilityRole prop and use the role prop instead.
*/
IMAGE: 'image',
},
/**
* Acceptable values for the `role` attribute on react native components.
*
* **IMPORTANT:** Not for use with the `accessibilityRole` prop, as it accepts different values, and new components
* should use the `role` prop instead.
*/
ROLE: {
/** Use for elements with important, time-sensitive information. */
ALERT: 'alert',
/** Use for elements that act as buttons. */
BUTTON: 'button',
/** Use for elements representing checkboxes. */
CHECKBOX: 'checkbox',
/** Use for elements that allow a choice from multiple options. */
COMBOBOX: 'combobox',
/** Use with scrollable lists to represent a grid layout. */
GRID: 'grid',
/** Use for section headers or titles. */
HEADING: 'heading',
/** Use for image elements. */
IMG: 'img',
/** Use for elements that navigate to other pages or content. */
LINK: 'link',
/** Use to identify a list of items. */
LIST: 'list',
/** Use for a list of choices or options. */
MENU: 'menu',
/** Use for a container of multiple menus. */
MENUBAR: 'menubar',
/** Use for items within a menu. */
MENUITEM: 'menuitem',
/** Use when no specific role is needed. */
NONE: 'none',
/** Use for elements that don't require a specific role. */
PRESENTATION: 'presentation',
/** Use for elements showing progress of a task. */
PROGRESSBAR: 'progressbar',
/** Use for radio buttons. */
RADIO: 'radio',
/** Use for groups of radio buttons. */
RADIOGROUP: 'radiogroup',
/** Use for scrollbar elements. */
SCROLLBAR: 'scrollbar',
/** Use for text fields that are used for searching. */
SEARCHBOX: 'searchbox',
/** Use for adjustable elements like sliders. */
SLIDER: 'slider',
/** Use for a button that opens a list of choices. */
SPINBUTTON: 'spinbutton',
/** Use for elements providing a summary of app conditions. */
SUMMARY: 'summary',
/** Use for on/off switch elements. */
SWITCH: 'switch',
ADJUSTABLE: 'slider',
IMAGE: 'img',
/** Use for tab elements in a tab list. */
TAB: 'tab',
/** Use for a list of tabs. */
TABLIST: 'tablist',
/** Use for timer elements. */
TIMER: 'timer',
/** Use for toolbars containing action buttons or components. */
TOOLBAR: 'toolbar',
},
TRANSLATION_KEYS: {
ATTACHMENT: 'common.attachment',
Expand Down
3 changes: 2 additions & 1 deletion src/components/AmountTextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function AmountTextInput(props) {
const styles = useThemeStyles();
return (
<TextInput
accessibilityLabel="Text input field"
disableKeyboard
autoGrow
hideFocusedState
Expand All @@ -55,7 +56,7 @@ function AmountTextInput(props) {
blurOnSubmit={false}
selection={props.selection}
onSelectionChange={props.onSelectionChange}
role={CONST.ACCESSIBILITY_ROLE.TEXT}
role={CONST.ROLE.PRESENTATION}
onKeyPress={props.onKeyPress}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function BaseAnchorForAttachmentsOnly(props) {
onPressOut={props.onPressOut}
onLongPress={(event) => showContextMenuForReport(event, anchor, report.reportID, action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report))}
accessibilityLabel={fileName}
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
role={CONST.ROLE.BUTTON}
>
<AttachmentView
source={sourceURLWithAuth}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ function BaseAnchorForCommentsOnly({onPressIn, onPressOut, href = '', rel = '',
}}
onPressIn={onPressIn}
onPressOut={onPressOut}
role={CONST.ACCESSIBILITY_ROLE.LINK}
role={CONST.ROLE.LINK}
accessibilityLabel={href}
>
<Tooltip text={href}>
<Text
ref={(el) => (linkRef = el)}
style={StyleSheet.flatten([style, defaultTextStyle])}
role={CONST.ACCESSIBILITY_ROLE.LINK}
role={CONST.ROLE.LINK}
hrefAttrs={{
rel,
target: isEmail || !linkProps.href ? '_self' : target,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function CarouselItem({item, isFocused, onPress}) {
<PressableWithoutFeedback
style={[styles.attachmentRevealButtonContainer]}
onPress={onPress}
role={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON}
accessibilityLabel={item.file.name || translate('attachmentView.unknownFilename')}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function AttachmentViewImage({source, file, isAuthTokenRequired, loadComplete, o
onPress={onPress}
disabled={loadComplete}
style={[styles.flex1, styles.flexRow, styles.alignSelfStretch]}
role={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON}
accessibilityLabel={file.name || translate('attachmentView.unknownFilename')}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function AttachmentViewImage({source, file, isAuthTokenRequired, isFocused, isUs
onPress={onPress}
disabled={loadComplete}
style={[styles.flex1, styles.flexRow, styles.alignSelfStretch]}
role={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON}
accessibilityLabel={file.name || translate('attachmentView.unknownFilename')}
>
{children}
Expand Down
2 changes: 1 addition & 1 deletion src/components/AvatarCropModal/AvatarCropModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ function AvatarCropModal(props) {
onLayout={initializeSliderContainer}
onPressIn={(e) => runOnUI(sliderOnPress)(e.nativeEvent.locationX)}
accessibilityLabel="slider"
role={CONST.ACCESSIBILITY_ROLE.ADJUSTABLE}
role={CONST.ROLE.SLIDER}
>
<Slider
sliderValue={translateSlider}
Expand Down
4 changes: 2 additions & 2 deletions src/components/AvatarWithDisplayName.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function AvatarWithDisplayName(props) {
<PressableWithoutFeedback
onPress={() => showActorDetails(props.report, props.shouldEnableDetailPageNavigation)}
accessibilityLabel={title}
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
role={CONST.ROLE.BUTTON}
>
{shouldShowSubscriptAvatar ? (
<SubscriptAvatar
Expand Down Expand Up @@ -165,7 +165,7 @@ function AvatarWithDisplayName(props) {
onPress={() => ReportUtils.navigateToDetailsPage(props.report)}
style={[styles.flexRow, styles.alignItemsCenter, styles.flex1]}
accessibilityLabel={title}
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
role={CONST.ROLE.BUTTON}
>
{headerView}
</PressableWithoutFeedback>
Expand Down
2 changes: 1 addition & 1 deletion src/components/AvatarWithImagePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class AvatarWithImagePicker extends React.Component {
<Tooltip text={this.props.translate('avatarWithImagePicker.editImage')}>
<PressableWithoutFeedback
onPress={() => this.setState((prev) => ({isMenuVisible: !prev.isMenuVisible}))}
role={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON}
accessibilityLabel={this.props.translate('avatarWithImagePicker.editImage')}
disabled={this.state.isAvatarCropModalOpen}
ref={this.anchorRef}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Badge({success = false, error = false, pressable = false, text, environ
<Wrapper
style={pressable ? wrapperStyles : wrapperStyles({focused: false, hovered: false, isDisabled: false, isScreenReaderActive: false, pressed: false})}
onPress={onPress}
role={pressable ? CONST.ACCESSIBILITY_ROLE.BUTTON : CONST.ACCESSIBILITY_ROLE.TEXT}
role={pressable ? CONST.ROLE.BUTTON : CONST.ROLE.PRESENTATION}
accessibilityLabel={pressable ? text : undefined}
aria-label={!pressable ? text : undefined}
accessible={false}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function Banner(props) {
<Tooltip text={props.translate('common.close')}>
<PressableWithFeedback
onPress={props.onClose}
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
role={CONST.ROLE.BUTTON}
accessibilityLabel={props.translate('common.close')}
>
<Icon src={Expensicons.Close} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/Button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function Button({
]}
id={id}
accessibilityLabel={accessibilityLabel}
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
role={CONST.ROLE.BUTTON}
hoverDimmingValue={1}
>
{renderContent()}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function Checkbox(props) {
ref={props.forwardedRef}
style={[StyleUtils.getCheckboxPressableStyle(props.containerBorderRadius + 2), props.style]} // to align outline on focus, border-radius of pressable should be 2px more than Checkbox
onKeyDown={handleSpaceKey}
role={CONST.ACCESSIBILITY_ROLE.CHECKBOX}
role={CONST.ROLE.CHECKBOX}
ariaChecked={props.isChecked}
accessibilityLabel={props.accessibilityLabel}
pressDimmingValue={1}
Expand Down
2 changes: 1 addition & 1 deletion src/components/CollapsibleSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function CollapsibleSection({title, children}: CollapsibleSectionProps) {
<PressableWithFeedback
onPress={toggleSection}
style={[styles.pb4, styles.flexRow]}
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
role={CONST.ROLE.BUTTON}
accessibilityLabel={title}
hoverDimmingValue={1}
pressDimmingValue={0.2}
Expand Down
2 changes: 1 addition & 1 deletion src/components/CurrencySymbolButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function CurrencySymbolButton({onCurrencyButtonPress, currencySymbol}) {
<PressableWithoutFeedback
onPress={onCurrencyButtonPress}
accessibilityLabel={translate('common.selectCurrency')}
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
role={CONST.ROLE.BUTTON}
>
<Text style={styles.iouAmountText}>{currencySymbol}</Text>
</PressableWithoutFeedback>
Expand Down
2 changes: 1 addition & 1 deletion src/components/DatePicker/index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const DatePicker = forwardRef(({value, defaultValue, label, placeholder, errorTe
<TextInput
label={label}
accessibilityLabel={label}
role={CONST.ACCESSIBILITY_ROLE.TEXT}
role={CONST.ROLE.PRESENTATION}
value={dateAsText}
forceActiveLabel
placeholder={placeholder}
Expand Down
2 changes: 1 addition & 1 deletion src/components/DatePicker/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function DatePicker({value, defaultValue, innerRef, onInputChange, preferredLoca
forceActiveLabel
label={label}
accessibilityLabel={label}
role={CONST.ACCESSIBILITY_ROLE.TEXT}
role={CONST.ROLE.PRESENTATION}
value={dateAsText}
placeholder={placeholder}
errorText={errorText}
Expand Down
2 changes: 1 addition & 1 deletion src/components/DatePicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function DatePicker({maxDate, minDate, onInputChange, innerRef, label, value, pl
onFocus={showDatepicker}
label={label}
accessibilityLabel={label}
role={CONST.ACCESSIBILITY_ROLE.TEXT}
role={CONST.ROLE.PRESENTATION}
onInputChange={setDate}
value={value}
placeholder={placeholder}
Expand Down
2 changes: 1 addition & 1 deletion src/components/EmojiPicker/CategoryShortcutButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function CategoryShortcutButton(props) {
onHoverOut={() => setIsHighlighted(false)}
style={({pressed}) => [StyleUtils.getButtonBackgroundColorStyle(getButtonState(false, pressed)), styles.categoryShortcutButton, isHighlighted && styles.emojiItemHighlighted]}
accessibilityLabel={`emojiPicker.headers.${props.code}`}
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
role={CONST.ROLE.BUTTON}
>
<Icon
fill={theme.icon}
Expand Down
2 changes: 1 addition & 1 deletion src/components/EmojiPicker/EmojiPickerButtonDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function EmojiPickerButtonDropdown(props) {
onPress={onPress}
id="emojiDropdownButton"
accessibilityLabel="statusEmoji"
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
role={CONST.ROLE.BUTTON}
>
{({hovered, pressed}) => (
<View style={styles.emojiPickerButtonDropdownContainer}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/EmojiPicker/EmojiPickerMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ function EmojiPickerMenu(props) {
<TextInput
label={translate('common.search')}
accessibilityLabel={translate('common.search')}
role={CONST.ACCESSIBILITY_ROLE.TEXT}
role={CONST.ROLE.PRESENTATION}
onChangeText={filterEmojis}
defaultValue=""
ref={searchInputRef}
Expand Down
2 changes: 1 addition & 1 deletion src/components/EmojiPicker/EmojiPickerMenu/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function EmojiPickerMenu({preferredLocale, onEmojiSelected, preferredSkinTone, t
<TextInput
label={translate('common.search')}
accessibilityLabel={translate('common.search')}
role={CONST.ACCESSIBILITY_ROLE.TEXT}
role={CONST.ROLE.PRESENTATION}
onChangeText={filterEmojis}
blurOnSubmit={filteredEmojis.length > 0}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/EmojiPicker/EmojiPickerMenuItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class EmojiPickerMenuItem extends PureComponent {
this.props.themeStyles.emojiItem,
]}
accessibilityLabel={this.props.emoji}
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
role={CONST.ROLE.BUTTON}
>
<Text style={[this.props.themeStyles.emojiText]}>{this.props.emoji}</Text>
</PressableWithoutFeedback>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class EmojiPickerMenuItem extends PureComponent {
this.props.themeStyles.emojiItem,
]}
accessibilityLabel={this.props.emoji}
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
role={CONST.ROLE.BUTTON}
>
<Text style={[this.props.themeStyles.emojiText]}>{this.props.emoji}</Text>
</PressableWithoutFeedback>
Expand Down
2 changes: 1 addition & 1 deletion src/components/EmojiPicker/EmojiSkinToneList.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function EmojiSkinToneList(props) {
onPress={toggleIsSkinToneListVisible}
style={[styles.flexRow, styles.alignSelfCenter, styles.justifyContentStart, styles.alignItemsCenter]}
accessibilityLabel={props.translate('emojiPicker.skinTonePickerLabel')}
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
role={CONST.ROLE.BUTTON}
>
<View style={[styles.emojiItem, styles.wAuto, styles.justifyContentCenter]}>
<Text style={[styles.emojiText, styles.ph2, styles.textNoWrap]}>{currentSkinTone.code}</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function ImageRenderer(props) {
ReportUtils.isArchivedRoom(report),
)
}
role={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON}
accessibilityLabel={translate('accessibilityHints.viewAttachment')}
>
<ThumbnailImage
Expand Down
Loading

0 comments on commit 2336f3b

Please sign in to comment.