Skip to content
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

Dropdown onChange callback should only be called when the selected value changes #3370

Closed
spencer-brown opened this issue Jan 10, 2019 · 8 comments

Comments

@spencer-brown
Copy link

Bug Report

Steps

  • Create a Dropdown with value and onChange props.
  • Click the Dropdown and then click outside of the value-displaying-box and dropdown list.

Expected Result

The onChange callback should not be fired because I haven't selected a new value. This is how HTML's select behaves.

Actual Result

The onChange callback is called even though the selected value has not changed.

Version

0.82.3

Testcase

https://codesandbox.io/s/5z379wy7ol

@husseyexplores
Copy link
Contributor

husseyexplores commented Jan 12, 2019

You can pass selectOnBlur={false} as a prop to prevent this behavior.
I'm not sure if this intentional (i.e passing selectOnBlur explicitly). I can work on this if this needs to behave as expected.
Edit: I personally think selectOnBlur should be false by default because that is the normal HTML Select element behavior.

@spencer-brown
Copy link
Author

ah, thanks @husseyexplores !

I agree with you - I think that it makes more sense for selectOnBlur to default to false for the sake of achieving parity w/ HTML.

@spencer-brown
Copy link
Author

This is still an issue beyond the blur case btw - if you click the already-selected item in the dropdown list, the onChange callback is called. This too is different than HTML's behavior.

@levithomason
Copy link
Member

levithomason commented Jan 17, 2019

Superb report, thanks much. The current dropdown calls onChange on blur even if the value doesn't change, which is certainly not correct. Here's an updated example comparing a native DOM select to the Dropdown: https://codesandbox.io/s/43r9899x4

We need to update the Dropdown to behave just as the regular HTML select in this regard.

@zarend
Copy link
Contributor

zarend commented Jan 18, 2019

#3391

@spencer-brown
Copy link
Author

@levithomason , how does @zarend 's PR look?

@layershifter
Copy link
Member

Was fixed in #3391 🎉

@spencer-brown
Copy link
Author

thanks @zarend @levithomason & @layershifter !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants