Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not render name attribute on INPUT if it is not supplied #7199

Merged
merged 1 commit into from
Jul 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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