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 7dc4cd4
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 31 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
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 @@ -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
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

0 comments on commit 7dc4cd4

Please sign in to comment.