Provide component reference in ReactDOMFiberTextarea warnings (#13361)

* Provide component reference if possible in ReactDOMFiberTextarea.js warning

* Nits
This commit is contained in:
Rauno Freiberg
2018-08-13 15:55:56 +01:00
committed by Dan Abramov
parent 714c78d5a1
commit 47e217a77d
2 changed files with 11 additions and 8 deletions
+7 -7
View File
@@ -399,12 +399,14 @@ describe('ReactDOMTextarea', () => {
});
it('should warn if value and defaultValue are specified', () => {
const InvalidComponent = () => (
<textarea value="foo" defaultValue="bar" readOnly={true} />
);
expect(() =>
ReactTestUtils.renderIntoDocument(
<textarea value="foo" defaultValue="bar" readOnly={true} />,
),
ReactTestUtils.renderIntoDocument(<InvalidComponent />),
).toWarnDev(
'Textarea elements must be either controlled or uncontrolled ' +
'InvalidComponent contains a textarea with both value and defaultValue props. ' +
'Textarea 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 textarea ' +
'and remove one of these props. More info: ' +
@@ -412,9 +414,7 @@ describe('ReactDOMTextarea', () => {
);
// No additional warnings are expected
ReactTestUtils.renderIntoDocument(
<textarea value="foo" defaultValue="bar" readOnly={true} />,
);
ReactTestUtils.renderIntoDocument(<InvalidComponent />);
});
it('should not warn about missing onChange in uncontrolled textareas', () => {
+4 -1
View File
@@ -11,6 +11,7 @@ import invariant from 'shared/invariant';
import warning from 'shared/warning';
import ReactControlledValuePropTypes from '../shared/ReactControlledValuePropTypes';
import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCurrentFiber';
let didWarnValDefaultVal = false;
@@ -70,11 +71,13 @@ export function initWrapperState(element: Element, props: Object) {
) {
warning(
false,
'Textarea elements must be either controlled or uncontrolled ' +
'%s contains a textarea with both value and defaultValue props. ' +
'Textarea 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 textarea ' +
'and remove one of these props. More info: ' +
'https://fb.me/react-controlled-components',
getCurrentFiberOwnerNameInDevOrNull() || 'A component',
);
didWarnValDefaultVal = true;
}