MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / updateOptions

Function updateOptions

code/communication/public/app.js:14547–14587  ·  view source on GitHub ↗
(node, multiple, propValue, setDefaultSelected)

Source from the content-addressed store, hash-verified

14545}
14546
14547function updateOptions(node, multiple, propValue, setDefaultSelected) {
14548 var options = node.options;
14549
14550 if (multiple) {
14551 var selectedValues = propValue;
14552 var selectedValue = {};
14553 for (var i = 0; i < selectedValues.length; i++) {
14554 // Prefix to avoid chaos with special keys.
14555 selectedValue['$' + selectedValues[i]] = true;
14556 }
14557 for (var _i = 0; _i < options.length; _i++) {
14558 var selected = selectedValue.hasOwnProperty('$' + options[_i].value);
14559 if (options[_i].selected !== selected) {
14560 options[_i].selected = selected;
14561 }
14562 if (selected && setDefaultSelected) {
14563 options[_i].defaultSelected = true;
14564 }
14565 }
14566 } else {
14567 // Do not set `select.value` as exact behavior isn't consistent across all
14568 // browsers for all cases.
14569 var _selectedValue = '' + propValue;
14570 var defaultSelected = null;
14571 for (var _i2 = 0; _i2 < options.length; _i2++) {
14572 if (options[_i2].value === _selectedValue) {
14573 options[_i2].selected = true;
14574 if (setDefaultSelected) {
14575 options[_i2].defaultSelected = true;
14576 }
14577 return;
14578 }
14579 if (defaultSelected === null && !options[_i2].disabled) {
14580 defaultSelected = options[_i2];
14581 }
14582 }
14583 if (defaultSelected !== null) {
14584 defaultSelected.selected = true;
14585 }
14586 }
14587}
14588
14589/**
14590 * Implements a <select> host component that allows optionally setting the

Callers 3

postMountWrapper$2Function · 0.70
postUpdateWrapperFunction · 0.70
restoreControlledState$2Function · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected