Skip to content

Commit

Permalink
fix: added close drawer accessibility tap area (#11184)
Browse files Browse the repository at this point in the history
**Motivation**

Currently, a user can tap the `Overlay` next to an open drawer to close
the drawer. This is useful in an Accessibility setting when swipe
actions are not obvious to the user. Unfortunately, it is not obvious to
someone with a visual deficit that this area can be tapped to close the
drawer, as this overlay does not have an accessibilityLabel prop
exposed.

This PR exposes an `accessibilityLabel` prop on this overlay component
and modifies existing accessibility props to allow for accessibility tap
permissions on the overlay component. It then surfaces this prop at the
`Drawer` level as `closeAccessibilityLabel`.
 
**Test plan**

Open up the example app with TalkBack (Android) or VoiceOver (iOS)
enabled. Tap on the overlay next to the drawer and observe that it will
now read out as "Close drawer".
  • Loading branch information
mikegarfinkle committed Feb 12, 2023
1 parent 99ff9f7 commit 061fb13
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions example/src/index.tsx
Expand Up @@ -230,6 +230,7 @@ export default function App() {
<Drawer.Navigator
screenOptions={{
drawerType: isLargeScreen ? 'permanent' : undefined,
overlayAccessibilityLabel: 'Close drawer',
}}
>
<Drawer.Screen
Expand Down
6 changes: 6 additions & 0 deletions packages/drawer/src/types.tsx
Expand Up @@ -171,6 +171,11 @@ export type DrawerNavigationOptions = HeaderOptions & {
*/
overlayColor?: string;

/**
* Screen readers will read this string when the user presses on the overlay adjacent to an opened drawer. Defaults to "Close drawer".
* **/
overlayAccessibilityLabel?: string;

/**
* Style object for the component wrapping the screen content.
*/
Expand Down Expand Up @@ -310,4 +315,5 @@ export type DrawerProps = {
swipeEdgeWidth: number;
swipeEnabled: boolean;
swipeVelocityThreshold: number;
overlayAccessibilityLabel?: string;
};
2 changes: 2 additions & 0 deletions packages/drawer/src/views/DrawerView.tsx
Expand Up @@ -113,6 +113,7 @@ function DrawerViewBase({
Platform.OS !== 'windows' &&
Platform.OS !== 'macos',
swipeMinDistance = 60,
overlayAccessibilityLabel,
} = descriptors[focusedRouteKey].options;

const [loaded, setLoaded] = React.useState([focusedRouteKey]);
Expand Down Expand Up @@ -296,6 +297,7 @@ function DrawerViewBase({
statusBarAnimation={drawerStatusBarAnimation}
keyboardDismissMode={keyboardDismissMode}
drawerType={drawerType}
overlayAccessibilityLabel={overlayAccessibilityLabel}
drawerPosition={drawerPosition}
drawerStyle={[
{
Expand Down
3 changes: 2 additions & 1 deletion packages/drawer/src/views/legacy/Drawer.tsx
Expand Up @@ -492,6 +492,7 @@ export default class DrawerView extends React.Component<DrawerProps> {
renderDrawerContent,
renderSceneContent,
gestureHandlerProps,
overlayAccessibilityLabel,
} = this.props;

const isOpen = drawerType === 'permanent' ? true : open;
Expand Down Expand Up @@ -582,6 +583,7 @@ export default class DrawerView extends React.Component<DrawerProps> {
<Overlay
progress={progress}
onPress={() => this.toggleDrawer(false)}
accessibilityLabel={overlayAccessibilityLabel}
style={overlayStyle as any}
accessibilityElementsHidden={!isOpen}
importantForAccessibility={
Expand Down Expand Up @@ -609,7 +611,6 @@ export default class DrawerView extends React.Component<DrawerProps> {
/>
)}
<Animated.View
accessibilityViewIsModal={isOpen && drawerType !== 'permanent'}
removeClippedSubviews={Platform.OS !== 'ios'}
onLayout={this.handleDrawerLayout}
style={[
Expand Down
16 changes: 14 additions & 2 deletions packages/drawer/src/views/legacy/Overlay.tsx
Expand Up @@ -18,10 +18,17 @@ const PROGRESS_EPSILON = 0.05;
type Props = React.ComponentProps<typeof Animated.View> & {
progress: Animated.Node<number>;
onPress: () => void;
accessibilityLabel?: string;
};

const Overlay = React.forwardRef(function Overlay(
{ progress, onPress, style, ...props }: Props,
{
progress,
onPress,
style,
accessibilityLabel = 'Close drawer',
...props
}: Props,
ref: React.Ref<Animated.View>
) {
const animatedStyle = {
Expand All @@ -48,7 +55,12 @@ const Overlay = React.forwardRef(function Overlay(
ref={ref}
style={[styles.overlay, overlayStyle, animatedStyle, style]}
>
<Pressable onPress={onPress} style={styles.pressable} />
<Pressable
onPress={onPress}
style={styles.pressable}
accessibilityRole="button"
accessibilityLabel={accessibilityLabel}
/>
</Animated.View>
);
});
Expand Down
3 changes: 2 additions & 1 deletion packages/drawer/src/views/modern/Drawer.tsx
Expand Up @@ -61,6 +61,7 @@ export default function Drawer({
swipeEdgeWidth,
swipeEnabled,
swipeVelocityThreshold,
overlayAccessibilityLabel,
}: DrawerProps) {
const getDrawerWidth = (): number => {
const { width = DEFAULT_DRAWER_WIDTH } =
Expand Down Expand Up @@ -378,11 +379,11 @@ export default function Drawer({
toggleDrawer({ open: false, isUserInitiated: true })
}
style={overlayStyle}
accessibilityLabel={overlayAccessibilityLabel}
/>
) : null}
</Animated.View>
<Animated.View
accessibilityViewIsModal={isOpen && drawerType !== 'permanent'}
removeClippedSubviews={Platform.OS !== 'ios'}
style={[
styles.container,
Expand Down
16 changes: 14 additions & 2 deletions packages/drawer/src/views/modern/Overlay.tsx
Expand Up @@ -10,10 +10,17 @@ const PROGRESS_EPSILON = 0.05;
type Props = React.ComponentProps<typeof Animated.View> & {
progress: Animated.SharedValue<number>;
onPress: () => void;
accessibilityLabel?: string;
};

const Overlay = React.forwardRef(function Overlay(
{ progress, onPress, style, ...props }: Props,
{
progress,
onPress,
style,
accessibilityLabel = 'Close drawer',
...props
}: Props,
ref: React.Ref<Animated.View>
) {
const animatedStyle = useAnimatedStyle(() => {
Expand Down Expand Up @@ -42,7 +49,12 @@ const Overlay = React.forwardRef(function Overlay(
style={[styles.overlay, overlayStyle, animatedStyle, style]}
animatedProps={animatedProps}
>
<Pressable onPress={onPress} style={styles.pressable} />
<Pressable
onPress={onPress}
style={styles.pressable}
accessibilityRole="button"
accessibilityLabel={accessibilityLabel}
/>
</Animated.View>
);
});
Expand Down

0 comments on commit 061fb13

Please sign in to comment.