MCPcopy Create free account
hub / github.com/Lobos/react-ui / updateOptions

Function updateOptions

docs/lib/react.js:8252–8281  ·  view source on GitHub ↗

* @param {ReactDOMComponent} inst * @param {boolean} multiple * @param {*} propValue A stringable (with `multiple`, a list of stringables). * @private

(inst, multiple, propValue)

Source from the content-addressed store, hash-verified

8250 * @private
8251 */
8252function updateOptions(inst, multiple, propValue) {
8253 var selectedValue, i;
8254 var options = ReactDOMComponentTree.getNodeFromInstance(inst).options;
8255
8256 if (multiple) {
8257 selectedValue = {};
8258 for (i = 0; i < propValue.length; i++) {
8259 selectedValue['' + propValue[i]] = true;
8260 }
8261 for (i = 0; i < options.length; i++) {
8262 var selected = selectedValue.hasOwnProperty(options[i].value);
8263 if (options[i].selected !== selected) {
8264 options[i].selected = selected;
8265 }
8266 }
8267 } else {
8268 // Do not set `select.value` as exact behavior isn't consistent across all
8269 // browsers for all cases.
8270 selectedValue = '' + propValue;
8271 for (i = 0; i < options.length; i++) {
8272 if (options[i].value === selectedValue) {
8273 options[i].selected = true;
8274 return;
8275 }
8276 }
8277 if (options.length) {
8278 options[0].selected = true;
8279 }
8280 }
8281}
8282
8283/**
8284 * Implements a <select> native component that allows optionally setting the

Callers 2

react.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…