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

Adding accessibility role and state to bottom bar #90

Merged
merged 2 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/navigators/createBottomTabNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import BottomTabBar, { type TabBarOptions } from '../views/BottomTabBar';
import ResourceSavingScene from '../views/ResourceSavingScene';

type Props = InjectedProps & {
getAccessibilityRole: (props: { route: any }) => string,
getAccessibilityStates: (props: { route: any }) => Array<string>,
lazy?: boolean,
tabBarComponent?: React.ComponentType<*>,
tabBarOptions?: TabBarOptions,
Expand Down Expand Up @@ -62,6 +64,8 @@ class TabNavigationView extends React.PureComponent<Props, State> {
screenProps,
getLabelText,
getAccessibilityLabel,
getAccessibilityRole,
getAccessibilityStates,
getTestID,
renderIcon,
onTabPress,
Expand Down Expand Up @@ -89,6 +93,8 @@ class TabNavigationView extends React.PureComponent<Props, State> {
getLabelText={getLabelText}
getButtonComponent={this._getButtonComponent}
getAccessibilityLabel={getAccessibilityLabel}
getAccessibilityRole={getAccessibilityRole}
getAccessibilityStates={getAccessibilityStates}
getTestID={getTestID}
renderIcon={renderIcon}
/>
Expand Down
23 changes: 23 additions & 0 deletions src/views/BottomTabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type Props = TabBarOptions & {
onTabPress: any,
onTabLongPress: any,
getAccessibilityLabel: (props: { route: any }) => string,
getAccessibilityRole: (props: { route: any }) => string,
getAccessibilityStates: (props: { route: any }) => Array<string>,
getButtonComponent: ({ route: any }) => any,
getLabelText: ({ route: any }) => any,
getTestID: (props: { route: any }) => string,
Expand All @@ -56,6 +58,8 @@ class TouchableWithoutFeedbackWrapper extends React.Component<*> {
onLongPress,
testID,
accessibilityLabel,
accessibilityRole,
accessibilityStates,
...props
} = this.props;

Expand All @@ -66,6 +70,8 @@ class TouchableWithoutFeedbackWrapper extends React.Component<*> {
testID={testID}
hitSlop={{ left: 15, right: 15, top: 0, bottom: 5 }}
accessibilityLabel={accessibilityLabel}
accessibilityRole={accessibilityRole}
accessibilityStates={accessibilityStates}
>
<View {...props} />
</TouchableWithoutFeedback>
Expand Down Expand Up @@ -220,9 +226,24 @@ class TabBarBottom extends React.Component<Props> {
{routes.map((route, index) => {
const focused = index === navigation.state.index;
const scene = { route, focused };

const accessibilityLabel = this.props.getAccessibilityLabel({
route,
});

const accessibilityRole =
this.props.getAccessibilityRole({
route,
}) || 'button';

let accessibilityStates = this.props.getAccessibilityStates({
route,
});

if (!accessibilityStates) {
accessibilityStates = focused ? ['selected'] : [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other accessibility states instead of selected/not selected do you have in mind?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selected and disabled are the only options allowed through the API, but this library would not really know if a tab is disabled (perhaps for an app's custom permissions?). If someone had a disabled tab, they could override getAccessibilityStates and return ['disabled'] or even ['selected', 'disabled'].

}

const testID = this.props.getTestID({ route });

const backgroundColor = focused
Expand All @@ -240,6 +261,8 @@ class TabBarBottom extends React.Component<Props> {
onLongPress={() => onTabLongPress({ route })}
testID={testID}
accessibilityLabel={accessibilityLabel}
accessibilityRole={accessibilityRole}
accessibilityStates={accessibilityStates}
style={[
styles.tab,
{ backgroundColor },
Expand Down