[Select] onClick not fired on menu items
See original GitHub issue- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
If you select the same value twice in a single Select, onChange
is not called the second time.
Expected Behavior 🤔
onChange
should be called every time a user selects a value, even if it’s the same value as before.
Steps to Reproduce 🕹
Here’s an example of functionality that worked in v4.9.8: https://codesandbox.io/s/frosty-cohen-gpk3y?file=/src/Demo.js
Here’s the same code not working in v4.9.9: https://codesandbox.io/s/hungry-neumann-y0ht0?file=/src/Demo.js
Steps:
- Click on the Select
- Select the value that is already selected
Context 🔦
We prefer to have the single Select behave in the same way as the multi Select- click on an already selected item to deselect it. Without an event, we can’t do that.
Related issue: https://github.com/mui-org/material-ui/issues/20351 Related PR: https://github.com/mui-org/material-ui/pull/20361
Your Environment 🌎
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
onclick not working for select menu options
I'm a beginner at HTML, and I have a problem with the onclick and the select (dropdown list). I know I did something...
Read more >mui/material-ui - [Select] onClick not fired on menu items
The issue is present in the latest release. I have searched the issues of this repository and believe that this is not a...
Read more >onclick handler is not fired correctly when it is in OPTION ...
Issue 5284: onclick handler is not fired correctly when it is in OPTION ... the "onclick" event is triggered in Chrome/Safari, the value...
Read more >Select not working - options not appearing on click
Hi, I am having trouble with the material select in my application. The element looks as if it is initializing as expected, however...
Read more >Element: click event - Web APIs | MDN
Add a dummy onclick="void(0)" attribute to the element or any of its ancestors up to but not including <body> . Use a typically...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
<kbd>Enter</kbd> will trigger onClick, we are good.
I think we might have to do a bit more with the
onKeyUp
part- I’ve tested passingonKeyUp
to eachMenuItem
, and it works for the arrow keys but not for the ‘Enter’ key. Example: https://codesandbox.io/s/divine-violet-jucyq?file=/src/Demo.jsMy guess is that the
Menu
closesonKeyDown
, so theMenuItem
isn’t around for theonKeyUp
event.