Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added close drawer accessibility tap area #11184

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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