-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Default to first non-disabled option for select elements #10456
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,14 +101,18 @@ function updateOptions( | |
// Do not set `select.value` as exact behavior isn't consistent across all | ||
// browsers for all cases. | ||
let selectedValue = '' + (propValue: string); | ||
let defaultSelected = null; | ||
for (let i = 0; i < options.length; i++) { | ||
if (options[i].value === selectedValue) { | ||
options[i].selected = true; | ||
return; | ||
} | ||
if (defaultSelected === null && !options[i].disabled) { | ||
defaultSelected = options[i]; | ||
} | ||
} | ||
if (options.length) { | ||
options[0].selected = true; | ||
if (defaultSelected !== null) { | ||
defaultSelected.selected = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know you didn't write all this, but the logic is hard to follow here...can we switch early to see if it's controlled? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it's a little dense, can you clarify what you mean by switching early to see if it's controlled? As far as I can tell, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking check if |
||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish I knew what wasn't consistent -- and where? Like was it IE8?. I'll write up an issue to do some archaeology here.
Totally unrelated to this PR 😛.