Skip to content

Commit

Permalink
refactor: use aria props to avoid deprecation warnings on web
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Mar 12, 2024
1 parent c54baf1 commit 4d16128
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 62 deletions.
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

0 comments on commit 4d16128

Please sign in to comment.