-
Notifications
You must be signed in to change notification settings - Fork 47k
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> behaviour should be consistent with DOM when <option>s values are identical #7203
Comments
Also there is #7054 which shouldn't be merged for the reasons given above |
What exactly do you think the desired behavior should be? As far as I can tell, React currently behaves about as reasonably as could be expected, which is why the proposal was to add a warning. Given the options:
And the selected |
@jimfb there is an example in comment I mentioned above #6959 (comment) So I think React should do the same — select proper option with value of that option |
@chicoxyzzy your example shows the behavior when a user selects an option manually. What is React supposed to do if setState({ value: 'vegetable' } Should it set it to |
@aweary exactly the same what DOM does: |
So specifically you're asking that it selects the first item from the list of That's reasonable, but I don't see how that change would make a warning any less helpful. |
So you propose to add warning and continue to violate consistency just because React doesn't follow the spec when it can (and should)? |
React should select valid options on mouse and keybord events |
I said it was reasonable for React to select the first item, just like your DOM example does. How would that be inconsistent? Adding a warning about using duplicate values in a controlled component is totally reasonable, |
@aweary try to change select by mouse or keyboard in both examples |
it shouldn't. It's ok to have non-unique values in options in markup |
I'm talking about controlled React components. You can render an uncontrolled |
@chicoxyzzy I think you're talking past Aweary, instead of trying to understand what he is saying. Everyone is in agreement that HTML allows non-unique values for uncontrolled inputs. The problem occurs when you try to specify one of those values using a controlled component. As per my comment: #7203 (comment) You said:
This does not make sense. There is no "proper option". There is only a set of possible options that specify a matching value. So you never actually answered my question: what do you believe React SHOULD do when the user specifies the value "vegetable"? |
React has to manage the value of the https://jsfiddle.net/kcbbxdej/ <select id="lol">
<option value="a">1</option>
<option value="a">2</option>
<option value="b">3</option>
</select> var id = document.getElementById('lol')
id.addEventListener('change', function(event) {
id.value = event.target.value
}) How is the |
OK. Shouldn't it warn only in case when Duplicate options could be desired business logic. In some cases warning will be emitted for proper (uncontrolled) select and not emitted for potentially dangerous controlled select (because in #7054 warning will be shown only once) |
OK this makes sense than. Thank you. I'll close this issue |
This is created as opposite to #6959.
There is a bug in React and it should be fixed to match DOM behaviour instead of solution proposed in #6959.
See #6959 (comment)
The text was updated successfully, but these errors were encountered: