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

Function updateOptions

code/new-context-api/public/app.js:13873–13913  ·  view source on GitHub ↗
(node, multiple, propValue, setDefaultSelected)

Source from the content-addressed store, hash-verified

13871}
13872
13873function updateOptions(node, multiple, propValue, setDefaultSelected) {
13874 var options = node.options;
13875
13876 if (multiple) {
13877 var selectedValues = propValue;
13878 var selectedValue = {};
13879 for (var i = 0; i < selectedValues.length; i++) {
13880 // Prefix to avoid chaos with special keys.
13881 selectedValue['$' + selectedValues[i]] = true;
13882 }
13883 for (var _i = 0; _i < options.length; _i++) {
13884 var selected = selectedValue.hasOwnProperty('$' + options[_i].value);
13885 if (options[_i].selected !== selected) {
13886 options[_i].selected = selected;
13887 }
13888 if (selected && setDefaultSelected) {
13889 options[_i].defaultSelected = true;
13890 }
13891 }
13892 } else {
13893 // Do not set `select.value` as exact behavior isn't consistent across all
13894 // browsers for all cases.
13895 var _selectedValue = '' + propValue;
13896 var defaultSelected = null;
13897 for (var _i2 = 0; _i2 < options.length; _i2++) {
13898 if (options[_i2].value === _selectedValue) {
13899 options[_i2].selected = true;
13900 if (setDefaultSelected) {
13901 options[_i2].defaultSelected = true;
13902 }
13903 return;
13904 }
13905 if (defaultSelected === null && !options[_i2].disabled) {
13906 defaultSelected = options[_i2];
13907 }
13908 }
13909 if (defaultSelected !== null) {
13910 defaultSelected.selected = true;
13911 }
13912 }
13913}
13914
13915/**
13916 * 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