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

refactor: use aria properties instead of accessibilityX #11848

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/bottom-tabs/src/views/BottomTabBar.tsx
Expand Up @@ -331,7 +331,7 @@ export function BottomTabBar({
{tabBarBackgroundElement}
</View>
<View
accessibilityRole="tablist"
role="tablist"
style={tabBarIsHorizontal ? styles.bottomContent : styles.sideContent}
>
{routes.map((route, index) => {
Expand Down
8 changes: 4 additions & 4 deletions packages/bottom-tabs/src/views/BottomTabItem.tsx
Expand Up @@ -141,7 +141,7 @@ export function BottomTabItem({
children,
style,
onPress,
accessibilityRole,
role,
...rest
}: BottomTabBarButtonProps) => {
return (
Expand All @@ -150,7 +150,7 @@ export function BottomTabItem({
android_ripple={{ borderless: true }}
pressOpacity={1}
href={href}
accessibilityRole={accessibilityRole}
role={role}
onPress={onPress}
style={style}
>
Expand Down Expand Up @@ -263,8 +263,8 @@ export function BottomTabItem({
onLongPress,
testID,
accessibilityLabel,
// FIXME: accessibilityRole: 'tab' doesn't seem to work as expected on iOS
accessibilityRole: Platform.select({ ios: 'button', default: 'tab' }),
// FIXME: role: 'tab' doesn't seem to work as expected on iOS
role: Platform.select({ ios: 'button', default: 'tab' }),
accessibilityState: { selected: focused },
// @ts-expect-error: keep for compatibility with older React Native versions
accessibilityStates: focused ? ['selected'] : [],
Expand Down
6 changes: 3 additions & 3 deletions packages/drawer/src/views/DrawerItem.tsx
Expand Up @@ -137,9 +137,9 @@ export function DrawerItem(props: Props) {
<PlatformPressable
testID={testID}
onPress={onPress}
accessibilityLabel={accessibilityLabel}
accessibilityRole="button"
accessibilityState={{ selected: focused }}
role="button"
aria-label={accessibilityLabel}
aria-selected={focused}
pressColor={pressColor}
pressOpacity={pressOpacity}
href={href}
Expand Down
2 changes: 1 addition & 1 deletion packages/elements/src/Header/HeaderButton.tsx
Expand Up @@ -19,7 +19,7 @@ export function HeaderButton({
<PlatformPressable
disabled={disabled}
href={href}
accessibilityLabel={accessibilityLabel}
aria-label={accessibilityLabel}
testID={testID}
onPress={onPress}
pressColor={pressColor}
Expand Down
2 changes: 1 addition & 1 deletion packages/elements/src/Header/HeaderTitle.tsx
Expand Up @@ -20,7 +20,7 @@ export function HeaderTitle({ tintColor, style, ...rest }: Props) {

return (
<Animated.Text
accessibilityRole="header"
role="heading"
aria-level="1"
numberOfLines={1}
{...rest}
Expand Down
4 changes: 1 addition & 3 deletions packages/elements/src/PlatformPressable.tsx
Expand Up @@ -88,9 +88,7 @@ export function PlatformPressable({
return (
<AnimatedPressable
accessible
accessibilityRole={
Platform.OS === 'web' && rest.href != null ? 'link' : 'button'
}
role={Platform.OS === 'web' && rest.href != null ? 'link' : 'button'}
onPress={disabled ? undefined : handlePress}
onPressIn={handlePressIn}
onPressOut={handlePressOut}
Expand Down
3 changes: 1 addition & 2 deletions packages/elements/src/Screen.tsx
Expand Up @@ -62,8 +62,7 @@ export function Screen(props: Props) {

return (
<Background
accessibilityElementsHidden={!focused}
importantForAccessibility={focused ? 'auto' : 'no-hide-descendants'}
aria-hidden={!focused}
style={[styles.container, style]}
// On Fabric we need to disable collapsing for the background to ensure
// that we won't render unnecessary views due to the view flattening.
Expand Down
8 changes: 1 addition & 7 deletions packages/native-stack/src/views/NativeStackView.native.tsx
Expand Up @@ -367,13 +367,7 @@ const SceneView = ({
{headerBackground()}
</View>
) : null}
<View
accessibilityElementsHidden={!focused}
importantForAccessibility={
focused ? 'auto' : 'no-hide-descendants'
}
style={styles.scene}
>
<View aria-hidden={!focused} style={styles.scene}>
<MaybeNestedStack
options={options}
route={route}
Expand Down
8 changes: 4 additions & 4 deletions packages/native/src/__tests__/Link.test.tsx
Expand Up @@ -51,9 +51,9 @@ it('renders link with href on web', () => {

expect(toJSON()).toMatchInlineSnapshot(`
<Text
accessibilityRole="link"
href="/bar/42"
onPress={[Function]}
role="link"
style={
[
{
Expand Down Expand Up @@ -82,9 +82,9 @@ it('renders link with href on web', () => {

expect(toJSON()).toMatchInlineSnapshot(`
<Text
accessibilityRole="link"
href="/foo"
onPress={[Function]}
role="link"
style={
[
{
Expand Down Expand Up @@ -146,9 +146,9 @@ it("doesn't navigate if default was prevented", () => {

expect(toJSON()).toMatchInlineSnapshot(`
<Text
accessibilityRole="link"
href="/bar/42"
onPress={[Function]}
role="link"
style={
[
{
Expand Down Expand Up @@ -177,9 +177,9 @@ it("doesn't navigate if default was prevented", () => {

expect(toJSON()).toMatchInlineSnapshot(`
<Text
accessibilityRole="link"
href="/bar/42"
onPress={[Function]}
role="link"
style={
[
{
Expand Down
2 changes: 1 addition & 1 deletion packages/native/src/useLinkProps.tsx
Expand Up @@ -137,7 +137,7 @@ export function useLinkProps<ParamList extends ReactNavigation.RootParamList>({
options?.config
)
: undefined),
accessibilityRole: 'link' as const,
role: 'link' as const,
onPress,
};
}
Expand Up @@ -380,14 +380,7 @@ export function Drawer({
>
<Animated.View style={[styles.content, contentAnimatedStyle]}>
<View
accessibilityElementsHidden={
isOpen && drawerType !== 'permanent'
}
importantForAccessibility={
isOpen && drawerType !== 'permanent'
? 'no-hide-descendants'
: 'auto'
}
aria-hidden={isOpen && drawerType !== 'permanent'}
style={styles.content}
>
{children}
Expand Down
7 changes: 1 addition & 6 deletions packages/react-native-drawer-layout/src/views/Drawer.tsx
Expand Up @@ -107,12 +107,7 @@ export function Drawer({
>
<View style={[styles.content, contentAnimatedStyle]}>
<View
accessibilityElementsHidden={isOpen && drawerType !== 'permanent'}
importantForAccessibility={
isOpen && drawerType !== 'permanent'
? 'no-hide-descendants'
: 'auto'
}
aria-hidden={isOpen && drawerType !== 'permanent'}
style={styles.content}
>
{children}
Expand Down
Expand Up @@ -29,9 +29,8 @@ export function Overlay({
const active = progress.value > PROGRESS_EPSILON;

return {
pointerEvents: active ? 'auto' : 'none',
accessibilityElementsHidden: !active,
importantForAccessibility: active ? 'auto' : 'no-hide-descendants',
'pointerEvents': active ? 'auto' : 'none',
'aria-hidden': !active,
} as const;
});

Expand All @@ -44,8 +43,8 @@ export function Overlay({
<Pressable
onPress={onPress}
style={styles.pressable}
accessibilityRole="button"
accessibilityLabel={accessibilityLabel}
role="button"
aria-label={accessibilityLabel}
/>
</Animated.View>
);
Expand Down
7 changes: 3 additions & 4 deletions packages/react-native-drawer-layout/src/views/Overlay.tsx
Expand Up @@ -18,14 +18,13 @@ export function Overlay({
{ opacity: open ? 1 : 0, pointerEvents: open ? 'auto' : 'none' },
style,
]}
accessibilityElementsHidden={!open}
importantForAccessibility={open ? 'auto' : 'no-hide-descendants'}
aria-hidden={!open}
>
<Pressable
onPress={onPress}
style={[styles.pressable, { pointerEvents: open ? 'auto' : 'none' }]}
accessibilityRole="button"
accessibilityLabel={accessibilityLabel}
role="button"
aria-label={accessibilityLabel}
/>
</View>
);
Expand Down
3 changes: 1 addition & 2 deletions packages/react-native-tab-view/src/SceneView.tsx
Expand Up @@ -75,8 +75,7 @@ export function SceneView<T extends Route>({

return (
<View
accessibilityElementsHidden={!focused}
importantForAccessibility={focused ? 'auto' : 'no-hide-descendants'}
aria-hidden={!focused}
style={[
styles.route,
// If we don't have the layout yet, make the focused screen fill the container
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-tab-view/src/TabBar.tsx
Expand Up @@ -676,7 +676,7 @@ export function TabBar<T extends Route>({
data={routes as Animated.WithAnimatedValue<T>[]}
keyExtractor={keyExtractor}
horizontal
accessibilityRole="tablist"
role="tablist"
keyboardShouldPersistTaps="handled"
scrollEnabled={scrollEnabled}
bounces={bounces}
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native-tab-view/src/TabBarItem.tsx
Expand Up @@ -215,9 +215,9 @@ const TabBarItemInternal = <T extends Route>({
android_ripple={android_ripple}
testID={testID}
accessible={accessible}
accessibilityLabel={accessibilityLabel}
accessibilityRole="tab"
accessibilityState={{ selected: isFocused }}
role="tab"
aria-label={accessibilityLabel}
aria-selected={isFocused}
pressColor={pressColor}
pressOpacity={pressOpacity}
unstable_pressDelay={0}
Expand Down
5 changes: 1 addition & 4 deletions packages/stack/src/views/Header/HeaderContainer.tsx
Expand Up @@ -165,10 +165,7 @@ export function HeaderContainer({
: undefined
}
pointerEvents={isFocused ? 'box-none' : 'none'}
accessibilityElementsHidden={!isFocused}
importantForAccessibility={
isFocused ? 'auto' : 'no-hide-descendants'
}
aria-hidden={!isFocused}
style={
// Avoid positioning the focused header absolutely
// Otherwise accessibility tools don't seem to be able to find it
Expand Down
3 changes: 1 addition & 2 deletions packages/stack/src/views/Stack/CardContainer.tsx
Expand Up @@ -248,8 +248,7 @@ function CardContainerInner({
gestureVelocityImpact={gestureVelocityImpact}
transitionSpec={transitionSpec}
styleInterpolator={cardStyleInterpolator}
accessibilityElementsHidden={!focused}
importantForAccessibility={focused ? 'auto' : 'no-hide-descendants'}
aria-hidden={!focused}
pointerEvents={active ? 'box-none' : pointerEvents}
pageOverflowEnabled={headerMode !== 'float' && presentation !== 'modal'}
preloaded={preloaded}
Expand Down