Skip to content

[ButtonBase] Keyboard triggered onClick on non-button element does not bubble #30144

@kmurgic

Description

@kmurgic

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

When a Menu has an onClick prop, clicking on a nested MenuItem triggers the onClick, but pressing spacebar or enter while a nested MenuItem is focused does not.

Expected behavior 🤔

When a Menu has an onClick prop, clicking on a nested MenuItem triggers the onClick, and so does pressing spacebar or enter while a nested MenuItem is focused

Steps to reproduce 🕹

https://codesandbox.io/s/basicmenu-material-demo-forked-34vqi?file=/demo.js:849-866
Steps:

  1. Click on the menu
  2. Click on a button - notice that "clicked menu" is logged to the console
  3. Click on the menu
  4. Navigate to a button using the mouse
  5. Press spacebar - notice that "clicked menu" is not logged to the console

Context 🔦

I was trying to create a custom ActionMenu component that by default closed whenever any buttons inside of it were clicked because I didn't want to have to call handleClose from the click handler of every single menu item.

Your environment 🌎

No response

Metadata

Metadata

Assignees

Labels

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions