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

<select>'s onChange event fires with incorrect selectedIndex, value #10420

Closed
martinsb opened this issue Aug 9, 2017 · 3 comments
Closed

<select>'s onChange event fires with incorrect selectedIndex, value #10420

martinsb opened this issue Aug 9, 2017 · 3 comments
Assignees
Milestone

Comments

@martinsb
Copy link

martinsb commented Aug 9, 2017

Do you want to request a feature or report a bug?
Report a bug.

What is the current behavior?
<select> element's onChange event is fired with incorrect selectedIndex and value, like it hasn't actually changed. This happens only if the element has been rendered under another React DOM root, see the example in the link below.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem
https://jsfiddle.net/martinsb/wd54vmmj/7/

What is the expected behavior?
onChange callback handlers should receive events with those values that user has actually selected. In the test case above, for example, when choosing "Two", I expect to have the following console output: Change event, selectedIndex: 1, value: 2

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
The bug is observed with react and react-dom packages version 16.0.0-beta.3. Latest stable version (15.6.1) works just fine.

@martinsb martinsb changed the title <select>'s onChange event fires with incorrect selectedIndex, value <select>'s onChange event fires with incorrect selectedIndex, value Aug 9, 2017
@sophiebits
Copy link
Collaborator

cc @sebmarkbage this is your ReactControlledComponent stuff probably

@sebmarkbage sebmarkbage added this to the 16.0 milestone Aug 11, 2017
@sebmarkbage sebmarkbage self-assigned this Aug 11, 2017
@sebmarkbage
Copy link
Collaborator

This is such a great bug report btw. Thank you so much!

@sebmarkbage
Copy link
Collaborator

I think the workaround, like with any unstable_renderSubtreeIntoContainer problem, is to use a Portal instead.

https://jsfiddle.net/319ced5z/1/

I'll take a look to see if this is something we can fix without it but Portals is definitely the way to go for these use cases.

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

No branches or pull requests

3 participants