Skip to content

Commit 347ca97

Browse files
authored
fix: use aria props instead of accessibilityX (#11848)
1 parent 8a098ed commit 347ca97

File tree

22 files changed

+50
-74
lines changed

22 files changed

+50
-74
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"prettierPath": null
6363
},
6464
"prettier": {
65-
"quoteProps": "consistent",
65+
"quoteProps": "as-needed",
6666
"tabWidth": 2,
6767
"useTabs": false,
6868
"singleQuote": true,

packages/bottom-tabs/src/types.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import type { HeaderOptions } from '@react-navigation/elements';
1+
import type {
2+
HeaderOptions,
3+
PlatformPressable,
4+
} from '@react-navigation/elements';
25
import type {
36
DefaultNavigatorOptions,
47
Descriptor,
@@ -15,7 +18,6 @@ import type * as React from 'react';
1518
import type {
1619
Animated,
1720
GestureResponderEvent,
18-
Pressable,
1921
StyleProp,
2022
TextStyle,
2123
ViewStyle,
@@ -431,7 +433,7 @@ export type BottomTabBarProps = {
431433
};
432434

433435
export type BottomTabBarButtonProps = Omit<
434-
React.ComponentProps<typeof Pressable>,
436+
React.ComponentProps<typeof PlatformPressable>,
435437
'style'
436438
> & {
437439
href?: string;

packages/bottom-tabs/src/views/BottomTabBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ export function BottomTabBar({
383383
{tabBarBackgroundElement}
384384
</View>
385385
<View
386-
accessibilityRole="tablist"
386+
role="tablist"
387387
style={sidebar ? styles.sideContent : styles.bottomContent}
388388
>
389389
{routes.map((route, index) => {

packages/bottom-tabs/src/views/BottomTabItem.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,21 +334,19 @@ export function BottomTabItem({
334334
onPress,
335335
onLongPress,
336336
testID,
337-
accessibilityLabel,
338-
accessibilityLargeContentTitle: labelString,
339-
accessibilityShowsLargeContentViewer: true,
340-
// FIXME: accessibilityRole: 'tab' doesn't seem to work as expected on iOS
341-
accessibilityRole: Platform.select({ ios: 'button', default: 'tab' }),
342-
accessibilityState: { selected: focused },
343-
// @ts-expect-error: keep for compatibility with older React Native versions
344-
accessibilityStates: focused ? ['selected'] : [],
345-
android_ripple: { borderless: true },
346-
hoverEffect:
337+
'aria-label': accessibilityLabel,
338+
'accessibilityLargeContentTitle': labelString,
339+
'accessibilityShowsLargeContentViewer': true,
340+
// FIXME: role: 'tab' doesn't seem to work as expected on iOS
341+
'role': Platform.select({ ios: 'button', default: 'tab' }),
342+
'aria-selected': focused,
343+
'android_ripple': { borderless: true },
344+
'hoverEffect':
347345
variant === 'material' || (sidebar && horizontal)
348346
? { color: colors.text }
349347
: undefined,
350-
pressOpacity: 1,
351-
style: [
348+
'pressOpacity': 1,
349+
'style': [
352350
styles.tab,
353351
{ flex, backgroundColor, borderRadius },
354352
sidebar
@@ -365,7 +363,7 @@ export function BottomTabItem({
365363
? styles.tabHorizontalUiKit
366364
: styles.tabVerticalUiKit,
367365
],
368-
children: (
366+
'children': (
369367
<React.Fragment>
370368
{renderIcon(scene)}
371369
{renderLabel(scene)}

packages/drawer/src/views/DrawerItem.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ export function DrawerItem(props: Props) {
139139
<PlatformPressable
140140
testID={testID}
141141
onPress={onPress}
142-
accessibilityLabel={accessibilityLabel}
143-
accessibilityRole="button"
144-
accessibilityState={{ selected: focused }}
142+
role="button"
143+
aria-label={accessibilityLabel}
144+
aria-selected={focused}
145145
pressColor={pressColor}
146146
pressOpacity={pressOpacity}
147147
hoverEffect={{ color }}

packages/elements/src/Header/HeaderButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function HeaderButtonInternal(
2323
ref={ref}
2424
disabled={disabled}
2525
href={href}
26-
accessibilityLabel={accessibilityLabel}
26+
aria-label={accessibilityLabel}
2727
testID={testID}
2828
onPress={onPress}
2929
pressColor={pressColor}

packages/elements/src/Header/HeaderSearchBar.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,8 @@ function HeaderSearchBarInternal(
157157
return (
158158
<Animated.View
159159
pointerEvents={visible ? 'auto' : 'none'}
160-
accessibilityLiveRegion="polite"
161-
accessibilityElementsHidden={!visible}
162-
importantForAccessibility={visible ? 'auto' : 'no-hide-descendants'}
160+
aria-live="polite"
161+
aria-hidden={!visible}
163162
style={[styles.container, { opacity: visibleAnim }, style]}
164163
>
165164
<View style={styles.searchbarContainer}>

packages/elements/src/Header/HeaderTitle.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function HeaderTitle({ tintColor, style, ...rest }: Props) {
1919

2020
return (
2121
<Animated.Text
22-
accessibilityRole="header"
22+
role="heading"
2323
aria-level="1"
2424
numberOfLines={1}
2525
{...rest}

packages/elements/src/PlatformPressable.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ function PlatformPressableInternal(
118118
<AnimatedPressable
119119
ref={ref}
120120
accessible
121-
accessibilityRole={
122-
Platform.OS === 'web' && rest.href != null ? 'link' : 'button'
123-
}
121+
role={Platform.OS === 'web' && rest.href != null ? 'link' : 'button'}
124122
onPress={disabled ? undefined : handlePress}
125123
onPressIn={handlePressIn}
126124
onPressOut={handlePressOut}

packages/elements/src/Screen.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ export function Screen(props: Props) {
6262

6363
return (
6464
<Background
65-
accessibilityElementsHidden={!focused}
66-
importantForAccessibility={focused ? 'auto' : 'no-hide-descendants'}
65+
aria-hidden={!focused}
6766
style={[styles.container, style]}
6867
// On Fabric we need to disable collapsing for the background to ensure
6968
// that we won't render unnecessary views due to the view flattening.

0 commit comments

Comments
 (0)