Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/FAB/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ type ItemProps = {
node: React.ComponentRef<typeof View> | 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.
Expand Down Expand Up @@ -291,6 +292,7 @@ const MenuItem = ({
onFocusItem,
registerRef,
onPress,
onAccessibilityEscape,
inMenu,
'aria-label': ariaLabel,
testID,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
/>
</AnimatedItem>
Expand Down
16 changes: 16 additions & 0 deletions src/components/__tests__/FABMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<FAB.Menu
expanded
onDismiss={onDismiss}
trigger={{ icon: 'plus' }}
items={makeItems()}
/>
);

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(
Expand Down
14 changes: 14 additions & 0 deletions src/components/__tests__/__snapshots__/FABMenu.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2224,6 +2224,7 @@ exports[`renders FAB.Menu open 1`] = `
accessible={true}
collapsable={false}
focusable={true}
onAccessibilityEscape={[MockFunction]}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
Expand Down Expand Up @@ -2485,6 +2486,7 @@ exports[`renders FAB.Menu open 1`] = `
accessible={true}
collapsable={false}
focusable={true}
onAccessibilityEscape={[MockFunction]}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
Expand Down Expand Up @@ -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]}
Expand Down Expand Up @@ -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]}
Expand Down Expand Up @@ -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]}
Expand Down Expand Up @@ -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]}
Expand Down Expand Up @@ -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]}
Expand Down Expand Up @@ -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]}
Expand Down Expand Up @@ -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]}
Expand Down Expand Up @@ -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]}
Expand Down Expand Up @@ -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]}
Expand Down Expand Up @@ -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]}
Expand Down Expand Up @@ -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]}
Expand Down Expand Up @@ -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]}
Expand Down
Loading