Skip to content

Commit

Permalink
Merge pull request #6341 from borisyankov/master
Browse files Browse the repository at this point in the history
Add more information to warning 'Input elements must be either controlled or uncontrolled'
  • Loading branch information
jimfb committed Apr 7, 2016
2 parents 1dc7c58 + 1018e50 commit 006058d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/renderers/dom/client/wrappers/ReactDOMInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ var ReactDOMInput = {
inst._currentElement._owner
);

var owner = inst._currentElement._owner;

if (props.valueLink !== undefined && !didWarnValueLink) {
warning(
false,
Expand All @@ -112,11 +114,14 @@ var ReactDOMInput = {
) {
warning(
false,
'%s contains an input of type %s with both checked and defaultChecked props. ' +
'Input elements must be either controlled or uncontrolled ' +
'(specify either the checked prop, or the defaultChecked prop, but not ' +
'both). Decide between using a controlled or uncontrolled input ' +
'element and remove one of these props. More info: ' +
'https://fb.me/react-controlled-components'
'https://fb.me/react-controlled-components',
owner && owner.getName() || 'A component',
props.type
);
didWarnCheckedDefaultChecked = true;
}
Expand All @@ -127,11 +132,14 @@ var ReactDOMInput = {
) {
warning(
false,
'%s contains an input of type %s with both value and defaultValue props. ' +
'Input elements must be either controlled or uncontrolled ' +
'(specify either the value prop, or the defaultValue prop, but not ' +
'both). Decide between using a controlled or uncontrolled input ' +
'element and remove one of these props. More info: ' +
'https://fb.me/react-controlled-components'
'https://fb.me/react-controlled-components',
owner && owner.getName() || 'A component',
props.type
);
didWarnValueDefaultValue = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ describe('ReactDOMInput', function() {
<input type="radio" checked={true} defaultChecked={true} readOnly={true} />
);
expect(console.error.argsForCall[0][0]).toContain(
'A component contains an input of type radio with both checked and defaultChecked props. ' +
'Input elements must be either controlled or uncontrolled ' +
'(specify either the checked prop, or the defaultChecked prop, but not ' +
'both). Decide between using a controlled or uncontrolled input ' +
Expand All @@ -440,6 +441,7 @@ describe('ReactDOMInput', function() {
<input type="text" value="foo" defaultValue="bar" readOnly={true} />
);
expect(console.error.argsForCall[0][0]).toContain(
'A component contains an input of type text with both value and defaultValue props. ' +
'Input elements must be either controlled or uncontrolled ' +
'(specify either the value prop, or the defaultValue prop, but not ' +
'both). Decide between using a controlled or uncontrolled input ' +
Expand Down

0 comments on commit 006058d

Please sign in to comment.