19
20
var didWarnValueDefaultValue = false;
21
22
-function updateOptionsIfPendingUpdateAndMounted() {
23
- if (this._rootNodeID && this._wrapperState.pendingUpdate) {
24
- this._wrapperState.pendingUpdate = false;
25
-
22
+function forceUpdateIfMounted() {
23
+ if (this._rootNodeID) {
24
var props = this._currentElement.props;
25
var value = props.value;
26
87
* @private
88
*/
89
function updateOptions(inst, multiple, propValue) {
92
- var selectedValue, i;
90
var options = ReactDOMComponentTree.getNodeFromInstance(inst).options;
91
92
if (multiple) {
96
- selectedValue = {};
97
- for (i = 0; i < propValue.length; i++) {
93
+ let selectedValue = {};
94
+ for (let i = 0; i < propValue.length; i++) {
95
selectedValue['' + propValue[i]] = true;
96
}
100
- for (i = 0; i < options.length; i++) {
97
+ for (let i = 0; i < options.length; i++) {
98
var selected = selectedValue.hasOwnProperty(options[i].value);
99
if (options[i].selected !== selected) {
100
options[i].selected = selected;
103
} else {
104
// Do not set `select.value` as exact behavior isn't consistent across all
105
// browsers for all cases.
109
- selectedValue = '' + propValue;
110
- for (i = 0; i < options.length; i++) {
106
+ let selectedValue = '' + propValue;
107
+ for (let i = 0; i < options.length; i++) {
108
if (options[i].value === selectedValue) {
109
options[i].selected = true;
110
return;
146
147
var value = props.value;
148
inst._wrapperState = {
152
- pendingUpdate: false,
149
initialValue: value != null ? value : props.defaultValue,
150
listeners: null,
151
onChange: _handleChange.bind(inst),
187
188
var value = props.value;
189
if (value != null) {
194
- inst._wrapperState.pendingUpdate = false;
190
updateOptions(inst, Boolean(props.multiple), value);
191
} else if (wasMultiple !== Boolean(props.multiple)) {
192
// For simplicity, reapply `defaultValue` if `multiple` is toggled.
207
returnValue = props.onChange.call(undefined, event);
208
}
209
215
- if (this._rootNodeID) {
216
- this._wrapperState.pendingUpdate = true;
217
- }
218
- ReactUpdates.asap(updateOptionsIfPendingUpdateAndMounted, this);
210
+ ReactUpdates.asap(forceUpdateIfMounted, this);
211
return returnValue;
212
}
213