Skip to content

Commit

Permalink
Do not render name attribute on INPUT if it is not supplied. Closes f…
Browse files Browse the repository at this point in the history
  • Loading branch information
okonet authored and usmanajmal committed Jul 11, 2016
1 parent 1a65221 commit db5ed90
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/renderers/dom/client/wrappers/ReactDOMInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,14 @@ var ReactDOMInput = {
// Reference: https://bugs.chromium.org/p/chromium/issues/detail?id=608416
// We need to temporarily unset name to avoid disrupting radio button groups.
var name = node.name;
node.name = undefined;
if (name !== '') {
node.name = '';
}
node.defaultChecked = !node.defaultChecked;
node.defaultChecked = !node.defaultChecked;
node.name = name;
if (name !== '') {
node.name = name;
}
},
};

Expand Down
33 changes: 30 additions & 3 deletions src/renderers/dom/client/wrappers/__tests__/ReactDOMInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,35 @@ describe('ReactDOMInput', function() {
expect(div.firstChild.getAttribute('defaultValue')).toBe(null);
});

it('should render name attribute if it is supplied', function() {
var container = document.createElement('div');
var node = ReactDOM.render(<input type="text" name="name" />, container);
expect(node.name).toBe('name');
expect(container.firstChild.getAttribute('name')).toBe('name');
});

it('should render name attribute if it is supplied for SSR', function() {
var element = <input type="text" name="name" />;
var markup = ReactDOMServer.renderToString(element);
var div = document.createElement('div');
div.innerHTML = markup;
expect(div.firstChild.getAttribute('name')).toBe('name');
});

it('should not render name attribute if it is not supplied', function() {
var container = document.createElement('div');
ReactDOM.render(<input type="text" />, container);
expect(container.firstChild.getAttribute('name')).toBe(null);
});

it('should not render name attribute if it is not supplied for SSR', function() {
var element = <input type="text" />;
var markup = ReactDOMServer.renderToString(element);
var div = document.createElement('div');
div.innerHTML = markup;
expect(div.firstChild.getAttribute('name')).toBe(null);
});

it('should display "foobar" for `defaultValue` of `objToString`', function() {
var objToString = {
toString: function() {
Expand Down Expand Up @@ -681,7 +710,7 @@ describe('ReactDOMInput', function() {
value="value"
defaultChecked={true}
checked={false}
onChange={() => null}
onChange={() => null}
/>, container);
expect(console.error.calls.count()).toBe(0);
});
Expand Down Expand Up @@ -727,10 +756,8 @@ describe('ReactDOMInput', function() {
'set type',
'set value',
'set value',
'set name',
'set checked',
'set checked',
'set name',
]);
});

Expand Down

0 comments on commit db5ed90

Please sign in to comment.