Skip to content

Commit

Permalink
Make the Menu close on Enter press
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak committed Sep 19, 2024
1 parent 9dbc42c commit 563d2b1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/mui-base/src/Menu/Item/useMenuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ export function useMenuItem(params: useMenuItem.Parameters): useMenuItem.ReturnV
event.defaultMuiPrevented = true;
}
},
onClick: (event: React.MouseEvent) => {
onClick: (event: React.MouseEvent | React.KeyboardEvent) => {
if (event.type === 'keydown') {
if ((event as React.KeyboardEvent).key === 'Enter') {
menuEvents.emit('close', event);
return;
}
}

if (closeOnClick) {
menuEvents.emit('close', event);
}
Expand Down

0 comments on commit 563d2b1

Please sign in to comment.