Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CONSTS to direct developers to use role instead of accessibilityRole (#31500) #74

Merged
merged 16 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
977257a
fix(ACCESSIBILITY_ROLE): Deprecate ACCESSIBLITY_ROLE
trevor-coleman Nov 17, 2023
0b1c973
fix(ACCESSIBILITY_ROLE): Add CONST.ROLE
trevor-coleman Nov 17, 2023
9fbda55
fix(ACCESSIBILITY_ROLE): fix formatting in JSDoc comment
trevor-coleman Nov 17, 2023
7743c4c
fix(ACCESSIBILITY_ROLE): redirect `role` props that point to `ACCESSI…
trevor-coleman Nov 17, 2023
30335de
fix(ACCESSIBILITY_ROLE): fix role attributes being passed invalid `im…
trevor-coleman Nov 17, 2023
ce403f1
fix(ACCESSIBILITY_ROLE): reset ADJUSTABLE TO 'adjustable'
trevor-coleman Nov 17, 2023
b72ac43
fix(ACCESSIBILITY_ROLE): set role prop to use CONST.ROLE instead of d…
trevor-coleman Nov 17, 2023
5811816
fix(ACCESSIBILITY_ROLE): set role prop to use CONST.ROLE instead of d…
trevor-coleman Nov 17, 2023
911c4b3
fix(ACCESSIBILITY_ROLE): set role prop to use CONST.ROLE instead of d…
trevor-coleman Nov 17, 2023
f3a8a4e
fix(ACCESSIBILITY_ROLE): set role props to use CONST.ROLE instead of …
trevor-coleman Nov 17, 2023
c2892ec
fix(ACCESSIBILITY_ROLE): replace reference to deprecatd CONST.ACCESSI…
trevor-coleman Nov 17, 2023
6931552
fix(ACCESSIBILITY_ROLE): replace accessibilityRole with role
trevor-coleman Nov 17, 2023
35eae47
fix(ACCESSIBILITY_ROLE): replace accessibilityRole with role
trevor-coleman Nov 17, 2023
de4b4c0
fix(ACCESSIBILITY_ROLE): replace accessibilityRole with role
trevor-coleman Nov 17, 2023
b60079b
prettier
trevor-coleman Nov 20, 2023
0639e66
Merge branch 'main' into trevorcoleman/accessibility-role
trevor-coleman Nov 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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