-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Select] onClick not fired on menu items #20709
Comments
I think is a duplicate of #20698 |
Thanks @marcosvega91, looks like this issue was brought up before. Following the comments, changing However, I can't seem to find the It might also be helpful to update the description of |
Hm, the |
Hi @tpeek you can try here codesandbox |
@marcosvega91 Your linked codesandbox is using |
I understand the problem. Is linked to #20361 |
Duplicate of #20698 |
@tpeek I don't think that we need to change anything about it. This replicates the behavior of a native select. If you need to respond to the click events, you can attach a listener to the menu items. |
Adding an Replacing the |
@tpeek Thanks for raising, it looks like a bug. Material-UI is supposed to forward all the events. What do you think of this patch? Do you want to submit a pull request? :) diff --git a/packages/material-ui/src/Select/SelectInput.js b/packages/material-ui/src/Select/SelectInput.js
index c6c6e3d1a..4d17eb618 100644
--- a/packages/material-ui/src/Select/SelectInput.js
+++ b/packages/material-ui/src/Select/SelectInput.js
@@ -140,6 +140,10 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
newValue = child.props.value;
}
+ if (child.props.onClick) {
+ child.props.onClick(event);
+ }
+
if (value === newValue) {
return;
}
@@ -252,9 +256,9 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
// the select to close immediately since we open on space keydown
event.preventDefault();
}
- const { onKeyUp } = child.props;
- if (typeof onKeyUp === 'function') {
- onKeyUp(event);
+
+ if (child.props.onKeyUp) {
+ child.props.onKeyUp(event);
}
},
role: 'option', |
I think we might have to do a bit more with the My guess is that the |
Enter will trigger onClick, we are good. |
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:
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: #20351
Related PR: #20361
Your Environment 🌎
The text was updated successfully, but these errors were encountered: