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: Context menu close should restore focus",
"packageName": "@fluentui/react-menu",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,9 @@ describe('Context menu', () => {
.get(menuTriggerSelector)
.click()
.get(menuSelector)
.should('not.exist');
.should('not.exist')
.get(menuTriggerSelector)
.should('have.focus');
});

it('should close on scroll outside', () => {
Expand All @@ -1081,6 +1083,21 @@ describe('Context menu', () => {
.get('body')
.trigger('wheel')
.get(menuSelector)
.should('not.exist');
.should('not.exist')
.get(menuTriggerSelector)
.should('have.focus');
});

it('should restore focus on escape', () => {
mount(<ContextMenuExample />);
cy.get(menuTriggerSelector)
.rightclick()
.get(menuSelector)
.should('exist')
.focused()
.type('{esc}')
.should('not.exist')
.get(menuTriggerSelector)
.should('have.focus');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export const useMenuTrigger_unstable = (props: MenuTriggerProps): MenuTriggerSta
id: triggerId,
...child?.props,
ref: useMergedRefs(triggerRef, child?.ref),
...restoreFocusTargetAttribute,
onMouseEnter: useEventCallback(mergeCallbacks(child?.props.onMouseEnter, onMouseEnter)),
onMouseLeave: useEventCallback(mergeCallbacks(child?.props.onMouseLeave, onMouseLeave)),
onContextMenu: useEventCallback(mergeCallbacks(child?.props.onContextMenu, onContextMenu)),
Expand All @@ -136,7 +137,6 @@ export const useMenuTrigger_unstable = (props: MenuTriggerProps): MenuTriggerSta
const triggerChildProps = {
'aria-haspopup': 'menu',
'aria-expanded': !open && !isSubmenu ? undefined : open,
...restoreFocusTargetAttribute,
...contextMenuProps,
onClick: useEventCallback(mergeCallbacks(child?.props.onClick, onClick)),
onKeyDown: useEventCallback(mergeCallbacks(child?.props.onKeyDown, onKeyDown)),
Expand Down