Skip to content

Commit 88c7a1b

Browse files
committed
Merge pull request facebook#3402 from vkramskikh/fix-empty-selects-with-value
Fix for empty <select> elements with value (cherry picked from commit 68a2f89)
1 parent 776e2de commit 88c7a1b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/browser/ui/dom/components/ReactDOMSelect.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ function updateOptions(component, propValue) {
8888
return;
8989
}
9090
}
91-
options[0].selected = true;
91+
if (options.length) {
92+
options[0].selected = true;
93+
}
9294
}
9395
}
9496

src/browser/ui/dom/components/__tests__/ReactDOMSelect-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ describe('ReactDOMSelect', function() {
4343
expect(node.value).toEqual('giraffe');
4444
});
4545

46+
it('should not throw with `defaultValue` and without children', function() {
47+
var stub = <select defaultValue="dummy"></select>;
48+
49+
expect(() => {
50+
ReactTestUtils.renderIntoDocument(stub);
51+
}).not.toThrow();
52+
});
53+
4654
it('should not control when using `defaultValue`', function() {
4755
var stub =
4856
<select defaultValue="giraffe">
@@ -100,6 +108,14 @@ describe('ReactDOMSelect', function() {
100108
expect(node.value).toEqual('gorilla');
101109
});
102110

111+
it('should not throw with `value` and without children', function() {
112+
var stub = <select value="dummy"></select>;
113+
114+
expect(() => {
115+
ReactTestUtils.renderIntoDocument(stub);
116+
}).not.toThrow();
117+
});
118+
103119
it('should allow setting `value` with multiple', function() {
104120
var stub =
105121
<select multiple={true} value={['giraffe', 'gorilla']}>

0 commit comments

Comments
 (0)