Skip to content

Commit 93700bb

Browse files
authored
[MenuItem][MacOS] Fix "onClick" being called twice when invoking menu item via ENTER / SPACE (#3933)
* Mark `onInvoke` event as handled for enter / space press to prevent duplicate call * Change files * Remove platform check
1 parent b1c9b93 commit 93700bb

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Mark `onInvoke` event as handled for enter / space press to prevent duplicate call",
4+
"packageName": "@fluentui-react-native/menu",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/components/Menu/src/MenuItem/useMenuItem.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ export const useMenuItem = (props: MenuItemProps): MenuItemInfo => {
3838
if (!disabled && (!isArrowKey || isArrowOpen)) {
3939
componentRef?.current?.blur();
4040
onClick?.(e);
41+
42+
// For RN, ENTER / SPACE keypresses are handled by both the `onKey` event handlers and `onPress` handler. Because we
43+
// pass this callback into both `onKeyDown` and `onPress` props, we need to mark the event as handled for ENTER / SPACE
44+
// key presses so that we don't have duplicate `onClick` calls.
45+
e.preventDefault();
4146
}
4247

4348
if (!hasSubmenu && !isArrowKey && !shouldPersist) {

0 commit comments

Comments
 (0)