Skip to content

Commit 448fa64

Browse files
committed
fix: fix accessibility label in bottom tab bar
1 parent 4e0e1f0 commit 448fa64

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

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

+21-10
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ export default class TabBarBottom extends React.Component<Props, State> {
119119
});
120120
};
121121

122+
private getLabelText = ({ route }: { route: Route<string> }) => {
123+
const { options } = this.props.descriptors[route.key];
124+
125+
return options.tabBarLabel !== undefined
126+
? options.tabBarLabel
127+
: options.title !== undefined
128+
? options.title
129+
: route.name;
130+
};
131+
122132
private renderLabel = ({
123133
route,
124134
focused,
@@ -139,14 +149,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
139149
return null;
140150
}
141151

142-
const { options } = this.props.descriptors[route.key];
143-
const label =
144-
options.tabBarLabel !== undefined
145-
? options.tabBarLabel
146-
: options.title !== undefined
147-
? options.title
148-
: route.name;
149-
152+
const label = this.getLabelText({ route });
150153
const horizontal = this.shouldUseHorizontalLabels();
151154
const color = focused ? activeTintColor : inactiveTintColor;
152155

@@ -354,6 +357,14 @@ export default class TabBarBottom extends React.Component<Props, State> {
354357
});
355358
};
356359

360+
const label = this.getLabelText({ route });
361+
const accessibilityLabel =
362+
options.tabBarAccessibilityLabel !== undefined
363+
? options.tabBarAccessibilityLabel
364+
: typeof label === 'string'
365+
? `${label}, tab, ${index + 1} of ${routes.length}`
366+
: undefined;
367+
357368
return (
358369
<NavigationContext.Provider
359370
key={route.key}
@@ -362,10 +373,10 @@ export default class TabBarBottom extends React.Component<Props, State> {
362373
{renderButton({
363374
onPress,
364375
onLongPress,
365-
testID: options.tabBarTestID,
366-
accessibilityLabel: options.tabBarAccessibilityLabel,
376+
accessibilityLabel,
367377
accessibilityRole: 'button',
368378
accessibilityStates: focused ? ['selected'] : [],
379+
testID: options.tabBarTestID,
369380
style: [
370381
styles.tab,
371382
{ backgroundColor },

0 commit comments

Comments
 (0)