Skip to content

Commit 1052ed6

Browse files
authored
fix: improve accessibility around Menu dismissing (#2028)
1 parent 4237fd6 commit 1052ed6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/components/Menu/Menu.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ type Props = {
4444
* Callback called when Menu is dismissed. The `visible` prop needs to be updated when this is called.
4545
*/
4646
onDismiss: () => void;
47+
/**
48+
* Accessibility label for the overlay. This is read by the screen reader when the user taps outside the menu.
49+
*/
50+
overlayAccessibilityLabel?: string;
4751
/**
4852
* Content of the `Menu`.
4953
*/
@@ -130,6 +134,7 @@ class Menu extends React.Component<Props, State> {
130134

131135
static defaultProps = {
132136
statusBarHeight: APPROX_STATUSBAR_HEIGHT,
137+
overlayAccessibilityLabel: 'Close menu',
133138
};
134139

135140
static getDerivedStateFromProps(nextProps: Props, prevState: State) {
@@ -339,6 +344,7 @@ class Menu extends React.Component<Props, State> {
339344
theme,
340345
statusBarHeight,
341346
onDismiss,
347+
overlayAccessibilityLabel,
342348
} = this.props;
343349

344350
const {
@@ -530,7 +536,11 @@ class Menu extends React.Component<Props, State> {
530536
{this.isAnchorCoord() ? null : anchor}
531537
{rendered ? (
532538
<Portal>
533-
<TouchableWithoutFeedback onPress={onDismiss}>
539+
<TouchableWithoutFeedback
540+
accessibilityLabel={overlayAccessibilityLabel}
541+
accessibilityRole="button"
542+
onPress={onDismiss}
543+
>
534544
<View style={StyleSheet.absoluteFill} />
535545
</TouchableWithoutFeedback>
536546
<View
@@ -541,6 +551,8 @@ class Menu extends React.Component<Props, State> {
541551
accessibilityViewIsModal={visible}
542552
style={[styles.wrapper, positionStyle, style]}
543553
pointerEvents={visible ? 'box-none' : 'none'}
554+
// @ts-ignore - FIX ME
555+
onAccessibilityEscape={onDismiss}
544556
>
545557
<Animated.View style={{ transform: positionTransforms }}>
546558
<Surface

0 commit comments

Comments
 (0)