MCPcopy Index your code
hub / github.com/microsoft/SandDance / updateOptions

Function updateOptions

docs/external/js/react-dom.development.js:2310–2360  ·  view source on GitHub ↗
(node, multiple, propValue, setDefaultSelected)

Source from the content-addressed store, hash-verified

2308 }
2309
2310 function updateOptions(node, multiple, propValue, setDefaultSelected) {
2311 var options = node.options;
2312
2313 if (multiple) {
2314 var selectedValues = propValue;
2315 var selectedValue = {};
2316
2317 for (var i = 0; i < selectedValues.length; i++) {
2318 // Prefix to avoid chaos with special keys.
2319 selectedValue['$' + selectedValues[i]] = true;
2320 }
2321
2322 for (var _i = 0; _i < options.length; _i++) {
2323 var selected = selectedValue.hasOwnProperty('$' + options[_i].value);
2324
2325 if (options[_i].selected !== selected) {
2326 options[_i].selected = selected;
2327 }
2328
2329 if (selected && setDefaultSelected) {
2330 options[_i].defaultSelected = true;
2331 }
2332 }
2333 } else {
2334 // Do not set `select.value` as exact behavior isn't consistent across all
2335 // browsers for all cases.
2336 var _selectedValue = toString(getToStringValue(propValue));
2337
2338 var defaultSelected = null;
2339
2340 for (var _i2 = 0; _i2 < options.length; _i2++) {
2341 if (options[_i2].value === _selectedValue) {
2342 options[_i2].selected = true;
2343
2344 if (setDefaultSelected) {
2345 options[_i2].defaultSelected = true;
2346 }
2347
2348 return;
2349 }
2350
2351 if (defaultSelected === null && !options[_i2].disabled) {
2352 defaultSelected = options[_i2];
2353 }
2354 }
2355
2356 if (defaultSelected !== null) {
2357 defaultSelected.selected = true;
2358 }
2359 }
2360 }
2361 /**
2362 * Implements a <select> host component that allows optionally setting the
2363 * props `value` and `defaultValue`. If `multiple` is false, the prop must be a

Callers 3

postMountWrapper$2Function · 0.85
postUpdateWrapperFunction · 0.85
restoreControlledState$1Function · 0.85

Calls 2

getToStringValueFunction · 0.85
toStringFunction · 0.70

Tested by

no test coverage detected