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

Function updateOptions

code/event-handlers/public/app.js:13842–13882  ·  view source on GitHub ↗
(node, multiple, propValue, setDefaultSelected)

Source from the content-addressed store, hash-verified

13840}
13841
13842function updateOptions(node, multiple, propValue, setDefaultSelected) {
13843 var options = node.options;
13844
13845 if (multiple) {
13846 var selectedValues = propValue;
13847 var selectedValue = {};
13848 for (var i = 0; i < selectedValues.length; i++) {
13849 // Prefix to avoid chaos with special keys.
13850 selectedValue['$' + selectedValues[i]] = true;
13851 }
13852 for (var _i = 0; _i < options.length; _i++) {
13853 var selected = selectedValue.hasOwnProperty('$' + options[_i].value);
13854 if (options[_i].selected !== selected) {
13855 options[_i].selected = selected;
13856 }
13857 if (selected && setDefaultSelected) {
13858 options[_i].defaultSelected = true;
13859 }
13860 }
13861 } else {
13862 // Do not set `select.value` as exact behavior isn't consistent across all
13863 // browsers for all cases.
13864 var _selectedValue = '' + propValue;
13865 var defaultSelected = null;
13866 for (var _i2 = 0; _i2 < options.length; _i2++) {
13867 if (options[_i2].value === _selectedValue) {
13868 options[_i2].selected = true;
13869 if (setDefaultSelected) {
13870 options[_i2].defaultSelected = true;
13871 }
13872 return;
13873 }
13874 if (defaultSelected === null && !options[_i2].disabled) {
13875 defaultSelected = options[_i2];
13876 }
13877 }
13878 if (defaultSelected !== null) {
13879 defaultSelected.selected = true;
13880 }
13881 }
13882}
13883
13884/**
13885 * 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