Skip to content
Closed
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
11 changes: 10 additions & 1 deletion packages/react-dom-bindings/src/client/ReactDOMTextarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@ export function updateTextarea(
}
// TOOO: This should respect disableInputAttributeSyncing flag.
if (defaultValue == null) {
if (node.defaultValue !== newValue) {
// Do not sync value and defaultValue if a minLength or maxLength constraint
// is set because this causes Chrome to skip validation.
// https://github.com/facebook/react/issues/19474
if (
node.defaultValue !== newValue &&
// $FlowFixMe[prop-missing]
node.minLength === -1 &&
// $FlowFixMe[prop-missing]
node.maxLength === -1
) {
node.defaultValue = newValue;
}
return;
Expand Down
26 changes: 26 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMTextarea-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,32 @@ describe('ReactDOMTextarea', () => {
expect(set.mock.calls.length).toBe(0);
});

it('does not update defaultValue of DOM node if minLength or maxLength are set', () => {
const container = document.createElement('div');
let node;
ReactDOM.render(
<textarea
ref={n => (node = n)}
value="foo"
onChange={emptyFunction}
minLength={10}
/>,
container,
);
expect(node.defaultValue).toBe('foo');

ReactDOM.render(
<textarea
ref={n => (node = n)}
value="food"
onChange={emptyFunction}
minLength={10}
/>,
container,
);
expect(node.defaultValue).toBe('foo');
});

describe('When given a Symbol value', () => {
it('treats initial Symbol value as an empty string', () => {
const container = document.createElement('div');
Expand Down