From 691bfd9b838483b8071610431f6071a421d8c63d Mon Sep 17 00:00:00 2001 From: NginxL <8777777+NginxL@users.noreply.github.com> Date: Sun, 6 Dec 2026 12:23:03 +0800 Subject: [PATCH] fix(fab): dismiss menu from item escape gesture --- src/components/FAB/Menu.tsx | 6 ++++++ src/components/__tests__/FABMenu.test.tsx | 16 ++++++++++++++++ .../__snapshots__/FABMenu.test.tsx.snap | 14 ++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/src/components/FAB/Menu.tsx b/src/components/FAB/Menu.tsx index b4041a2459..0069458c09 100644 --- a/src/components/FAB/Menu.tsx +++ b/src/components/FAB/Menu.tsx @@ -261,6 +261,7 @@ type ItemProps = { node: React.ComponentRef | null ) => void; onPress: (e: GestureResponderEvent) => void; + onAccessibilityEscape?: () => void; /** * Whether the item sits in a `role="menu"` on the web, which makes it a * `menuitem`. Otherwise it is a button. @@ -291,6 +292,7 @@ const MenuItem = ({ onFocusItem, registerRef, onPress, + onAccessibilityEscape, inMenu, 'aria-label': ariaLabel, testID, @@ -392,6 +394,7 @@ const MenuItem = ({ ref={itemRef} borderless onPress={onPress} + onAccessibilityEscape={onAccessibilityEscape} focusRing="none" // On native the press matches the hover and focus layers, as in // `Button`. On web `TouchableRipple` paints its own hover tint on @@ -994,6 +997,9 @@ const Menu = ({ inMenu={isMenu} aria-label={item['aria-label'] ?? item.label} onPress={handleItemPress(item)} + onAccessibilityEscape={ + effectiveExpanded ? onDismiss : undefined + } testID={item.testID} /> diff --git a/src/components/__tests__/FABMenu.test.tsx b/src/components/__tests__/FABMenu.test.tsx index 44159cd48b..5bd4e02798 100644 --- a/src/components/__tests__/FABMenu.test.tsx +++ b/src/components/__tests__/FABMenu.test.tsx @@ -491,6 +491,22 @@ describe('dismissing the menu', () => { expect(onDismiss).toHaveBeenCalledTimes(1); }); + it('calls onDismiss on the screen reader escape gesture from a focused item', async () => { + const onDismiss = jest.fn(); + await render( + + ); + + await fireEvent(screen.getByTestId('item-0'), 'accessibilityEscape'); + + expect(onDismiss).toHaveBeenCalledTimes(1); + }); + it('ignores the screen reader escape gesture while closed', async () => { const onDismiss = jest.fn(); await render( diff --git a/src/components/__tests__/__snapshots__/FABMenu.test.tsx.snap b/src/components/__tests__/__snapshots__/FABMenu.test.tsx.snap index 8fe4c9a3b3..9f8b62eeaa 100644 --- a/src/components/__tests__/__snapshots__/FABMenu.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/FABMenu.test.tsx.snap @@ -2224,6 +2224,7 @@ exports[`renders FAB.Menu open 1`] = ` accessible={true} collapsable={false} focusable={true} + onAccessibilityEscape={[MockFunction]} onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -2485,6 +2486,7 @@ exports[`renders FAB.Menu open 1`] = ` accessible={true} collapsable={false} focusable={true} + onAccessibilityEscape={[MockFunction]} onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -3206,6 +3208,7 @@ exports[`renders FAB.Menu with 6 items 1`] = ` accessible={true} collapsable={false} focusable={true} + onAccessibilityEscape={[MockFunction]} onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -3467,6 +3470,7 @@ exports[`renders FAB.Menu with 6 items 1`] = ` accessible={true} collapsable={false} focusable={true} + onAccessibilityEscape={[MockFunction]} onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -3728,6 +3732,7 @@ exports[`renders FAB.Menu with 6 items 1`] = ` accessible={true} collapsable={false} focusable={true} + onAccessibilityEscape={[MockFunction]} onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -3989,6 +3994,7 @@ exports[`renders FAB.Menu with 6 items 1`] = ` accessible={true} collapsable={false} focusable={true} + onAccessibilityEscape={[MockFunction]} onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -4250,6 +4256,7 @@ exports[`renders FAB.Menu with 6 items 1`] = ` accessible={true} collapsable={false} focusable={true} + onAccessibilityEscape={[MockFunction]} onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -4511,6 +4518,7 @@ exports[`renders FAB.Menu with 6 items 1`] = ` accessible={true} collapsable={false} focusable={true} + onAccessibilityEscape={[MockFunction]} onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -5233,6 +5241,7 @@ exports[`renders FAB.Menu with center alignment 1`] = ` accessible={true} collapsable={false} focusable={true} + onAccessibilityEscape={[MockFunction]} onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -5494,6 +5503,7 @@ exports[`renders FAB.Menu with center alignment 1`] = ` accessible={true} collapsable={false} focusable={true} + onAccessibilityEscape={[MockFunction]} onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -6214,6 +6224,7 @@ exports[`renders FAB.Menu with items having icons 1`] = ` accessible={true} collapsable={false} focusable={true} + onAccessibilityEscape={[MockFunction]} onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -6504,6 +6515,7 @@ exports[`renders FAB.Menu with items having icons 1`] = ` accessible={true} collapsable={false} focusable={true} + onAccessibilityEscape={[MockFunction]} onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -7255,6 +7267,7 @@ exports[`renders FAB.Menu with start alignment 1`] = ` accessible={true} collapsable={false} focusable={true} + onAccessibilityEscape={[MockFunction]} onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -7516,6 +7529,7 @@ exports[`renders FAB.Menu with start alignment 1`] = ` accessible={true} collapsable={false} focusable={true} + onAccessibilityEscape={[MockFunction]} onBlur={[Function]} onClick={[Function]} onFocus={[Function]}