Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Commit

Permalink
fix: fix accessibility label in bottom tab bar
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Dec 9, 2019
1 parent 4e0e1f0 commit 448fa64
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions packages/bottom-tabs/src/views/BottomTabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ export default class TabBarBottom extends React.Component<Props, State> {
});
};

private getLabelText = ({ route }: { route: Route<string> }) => {
const { options } = this.props.descriptors[route.key];

return options.tabBarLabel !== undefined
? options.tabBarLabel
: options.title !== undefined
? options.title
: route.name;
};

private renderLabel = ({
route,
focused,
Expand All @@ -139,14 +149,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
return null;
}

const { options } = this.props.descriptors[route.key];
const label =
options.tabBarLabel !== undefined
? options.tabBarLabel
: options.title !== undefined
? options.title
: route.name;

const label = this.getLabelText({ route });
const horizontal = this.shouldUseHorizontalLabels();
const color = focused ? activeTintColor : inactiveTintColor;

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

const label = this.getLabelText({ route });
const accessibilityLabel =
options.tabBarAccessibilityLabel !== undefined
? options.tabBarAccessibilityLabel
: typeof label === 'string'
? `${label}, tab, ${index + 1} of ${routes.length}`
: undefined;

return (
<NavigationContext.Provider
key={route.key}
Expand All @@ -362,10 +373,10 @@ export default class TabBarBottom extends React.Component<Props, State> {
{renderButton({
onPress,
onLongPress,
testID: options.tabBarTestID,
accessibilityLabel: options.tabBarAccessibilityLabel,
accessibilityLabel,
accessibilityRole: 'button',
accessibilityStates: focused ? ['selected'] : [],
testID: options.tabBarTestID,
style: [
styles.tab,
{ backgroundColor },
Expand Down

0 comments on commit 448fa64

Please sign in to comment.