Skip to content

Commit

Permalink
fix: added close accessibility tap area
Browse files Browse the repository at this point in the history
  • Loading branch information
mikegarfinkle committed Feb 1, 2023
1 parent f935766 commit 36ecb77
Show file tree
Hide file tree
Showing 7 changed files with 27 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,
closeAccessibilityLabel: 'Close drawer',
}}
>
<Drawer.Screen
Expand Down
5 changes: 5 additions & 0 deletions packages/drawer/src/types.tsx
Expand Up @@ -220,6 +220,10 @@ export type DrawerNavigationOptions = HeaderOptions & {
* Only supported on iOS and Android.
*/
freezeOnBlur?: boolean;
/**
* If set, screen readers will read out this string when the user presses on the overlay adjacent to an opened drawer, which will close the drawer.
* **/
closeAccessibilityLabel?: string;
};

export type DrawerContentComponentProps = {
Expand Down Expand Up @@ -310,4 +314,5 @@ export type DrawerProps = {
swipeEdgeWidth: number;
swipeEnabled: boolean;
swipeVelocityThreshold: number;
closeAccessibilityLabel?: 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,
closeAccessibilityLabel,
} = 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}
closeAccessibilityLabel={closeAccessibilityLabel}
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,
closeAccessibilityLabel,
} = 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={closeAccessibilityLabel}
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
9 changes: 7 additions & 2 deletions packages/drawer/src/views/legacy/Overlay.tsx
Expand Up @@ -18,10 +18,11 @@ 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, ...props }: Props,
ref: React.Ref<Animated.View>
) {
const animatedStyle = {
Expand All @@ -48,7 +49,11 @@ 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}
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,
closeAccessibilityLabel,
}: 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={closeAccessibilityLabel}
/>
) : null}
</Animated.View>
<Animated.View
accessibilityViewIsModal={isOpen && drawerType !== 'permanent'}
removeClippedSubviews={Platform.OS !== 'ios'}
style={[
styles.container,
Expand Down
10 changes: 8 additions & 2 deletions packages/drawer/src/views/modern/Overlay.tsx
Expand Up @@ -10,10 +10,11 @@ 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, ...props }: Props,
ref: React.Ref<Animated.View>
) {
const animatedStyle = useAnimatedStyle(() => {
Expand Down Expand Up @@ -42,7 +43,12 @@ const Overlay = React.forwardRef(function Overlay(
style={[styles.overlay, overlayStyle, animatedStyle, style]}
animatedProps={animatedProps}
>
<Pressable onPress={onPress} style={styles.pressable} />
<Pressable
accessible
onPress={onPress}
style={styles.pressable}
accessibilityLabel={accessibilityLabel}
/>
</Animated.View>
);
});
Expand Down

0 comments on commit 36ecb77

Please sign in to comment.