Skip to content

Commit 3f8e6e0

Browse files
committed
fix event propagation when in contextual help or on submenutrigger
fixes case where arrowLeft was propagating through contextualhelp dialogs which we only want to have be closed via ESC. Also fixes event propagation for default cases for submenu triggers so that we can call it in useMenuItem useKeyboard. Now we still properly close only the submenu trigger menu when focus is on the trigger and the submenu is open
1 parent 5bd7cb7 commit 3f8e6e0

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

packages/@react-aria/menu/src/useMenuItem.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,11 @@ export function useMenuItem<T>(props: AriaMenuItemProps, state: TreeState<T>, re
248248
}
249249
break;
250250
default:
251-
e.continuePropagation();
251+
if (!isTrigger) {
252+
e.continuePropagation();
253+
}
254+
255+
onKeyDown?.(e);
252256
break;
253257
}
254258
},
@@ -265,7 +269,7 @@ export function useMenuItem<T>(props: AriaMenuItemProps, state: TreeState<T>, re
265269
// Key down from useSubmenuTrigger's submenuTriggerProps is not incorporated into useKeyboard here since we
266270
// cannot sufficiently distinguish when propagation should be continued or stopped in this section of code.
267271
// It should only stop propagation if handling the ArrowRight case when the submenutrigger's menu is open and focus is on the trigger,
268-
...mergeProps(domProps, itemProps, pressProps, hoverProps, keyboardProps, focusProps, {onKeyDown, onKeyUp}),
272+
...mergeProps(domProps, itemProps, pressProps, hoverProps, keyboardProps, focusProps),
269273
tabIndex: itemProps.tabIndex != null ? -1 : undefined
270274
},
271275
labelProps: {

packages/@react-aria/menu/src/useSubmenuTrigger.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ export function UNSTABLE_useSubmenuTrigger<T>(props: AriaSubmenuTriggerProps, st
9090
let submenuKeyDown = (e: KeyboardEvent) => {
9191
switch (e.key) {
9292
case 'ArrowLeft':
93-
if (direction === 'ltr') {
93+
if (direction === 'ltr' && e.currentTarget.contains(e.target as Element)) {
9494
e.stopPropagation();
9595
onSubmenuClose();
9696
ref.current.focus();
9797
}
9898
break;
9999
case 'ArrowRight':
100-
if (direction === 'rtl') {
100+
if (direction === 'rtl' && e.currentTarget.contains(e.target as Element)) {
101101
e.stopPropagation();
102102
onSubmenuClose();
103103
ref.current.focus();
@@ -132,8 +132,9 @@ export function UNSTABLE_useSubmenuTrigger<T>(props: AriaSubmenuTriggerProps, st
132132
onSubmenuOpen('first');
133133
}
134134
} else if (state.isOpen) {
135-
e.stopPropagation();
136135
onSubmenuClose();
136+
} else {
137+
e.continuePropagation();
137138
}
138139
}
139140

@@ -147,11 +148,18 @@ export function UNSTABLE_useSubmenuTrigger<T>(props: AriaSubmenuTriggerProps, st
147148
onSubmenuOpen('first');
148149
}
149150
} else if (state.isOpen) {
150-
e.stopPropagation();
151151
onSubmenuClose();
152+
} else {
153+
e.continuePropagation();
152154
}
153155
}
154156
break;
157+
case 'Escape':
158+
state.closeAll();
159+
break;
160+
default:
161+
e.continuePropagation();
162+
break;
155163
}
156164
};
157165

0 commit comments

Comments
 (0)