Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: Menu trigger should be focused when menu is closed with keyboard",
"packageName": "@fluentui/react-menu",
"email": "[email protected]",
"dependentChangeType": "patch"
}
9 changes: 8 additions & 1 deletion packages/react-components/react-menu/e2e/Menu.e2e.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,14 @@ describe('Menu', () => {
</MenuPopover>
</Menu>,
);
cy.get(menuTriggerSelector).click().focused().type('{esc}').get(menuSelector).should('not.exist');
cy.get(menuTriggerSelector)
.click()
.focused()
.type('{esc}')
.get(menuSelector)
.should('not.exist')
.get(menuTriggerSelector)
Copy link
Contributor Author

@ling1726 ling1726 Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These situations should now be caught with tests

.should('be.focused');
});

it('should be dismissed on outside click', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@ const useMenuOpenState = (
state.setContextTarget(undefined);
}

if (e.type === 'keydown' && (e as React.KeyboardEvent<HTMLElement>).key === Tab) {
if (e.type === 'keydown') {
shouldHandleKeyboardRef.current = true;
shouldHandleTabRef.current = true;
pressedShiftRef.current = (e as React.KeyboardEvent<HTMLElement>).shiftKey;
if ((e as React.KeyboardEvent<HTMLElement>).key === Tab) {
shouldHandleTabRef.current = true;
pressedShiftRef.current = (e as React.KeyboardEvent<HTMLElement>).shiftKey;
}
}

if (data.bubble) {
Expand Down