@samitouri / QOS-React-2 / commits / eaa68b8e6b

Fix select switching to multiple in IE

This one was an actual behavioral bug rather than a bug with the tests; our intention was that the first element from the `defaultValue` array would remain selected but IE seemed to be choosing the last one instead. Now we set the value for uncontrolled components in componentDidUpdate when switching from multiple to non-multiple to ensure that a consistent option gets selected. Test Plan: Ran the ReactDOMSelect tests in jest, phantomjs, IE10, Chrome, and Firefox. Also tested an uncontrolled select manually to make sure that nothing crazy happened when switching between options.

Ben Alpert committed Jun 7, 2014 at 19:13 UTC eaa68b8e6b9c2628ecc1f841a162872cb8fcb18a
1 file changed +4 -2
src/browser/ui/dom/components/ReactDOMSelect.js
+4 -2
@@ -141,9 +141,11 @@ var ReactDOMSelect = ReactCompositeComponent.createClass({
141 updateOptions(this, LinkedValueUtils.getValue(this));
142 },
143
144 - componentDidUpdate: function() {
144 + componentDidUpdate: function(prevProps) {
145 var value = LinkedValueUtils.getValue(this);
146 - if (value != null) {
146 + var prevMultiple = !!prevProps.multiple;
147 + var multiple = !!this.props.multiple;
148 + if (value != null || prevMultiple !== multiple) {
149 updateOptions(this, value);
150 }
151 },