mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Provide component reference in ReactDOMFiberTextarea warnings (#13361)
* Provide component reference if possible in ReactDOMFiberTextarea.js warning * Nits
This commit is contained in:
committed by
Dan Abramov
parent
714c78d5a1
commit
47e217a77d
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user