Description
Hi,
thank you very much for what you do and you've been doing so far.
I've been working on some form validations via the Validation Constraints API and I've noticed that event.target.validity
read-only object doesn't get updated and is always valid although some constraints are set when the value
attribute is set to the Textarea
.
On the other hand, when value
is passed as children
validity
gets updated as expected but I'm being warned to Warning: Use the defaultValue or value props instead of setting children on <textarea>
React version: 16.13.1
Steps To Reproduce
Here's how you can reproduce:
-
setup this basic app component with one
Textarea
element, set some constraints and add thevalue
attribute as you normally would on any form. -
add another
Textarea
element but instead of passing value as an attribute pass it aschildren
see code below
import React, { useState } from 'react';
function App() {
const [state, setState] = useState({
first: '',
second: '',
});
function handleTextChange({ target }) {
const { name, value, validity } = target;
setState({
[name]: value,
});
console.log(`${name} validity:`, validity);
}
return (
<div className="App">
<textarea
name="first"
placeholder="First"
value={state.first}
onChange={handleTextChange}
required={true}
minLength={10}
/>
<textarea
name="second"
placeholder="Second"
onChange={handleTextChange}
required={true}
minLength={10}
>
{state.second}
</textarea>
</div>
);
}
export default App;
-
Open your console
-
Type at least one character into the first
Textarea
see screenshot
-
Type at least one character into the second
Textarea
see screenshot
The current behavior
You'll notice that the first Textarea
ignores the validation constraints set
The expected behavior
Validation constraints should be set and field should be invalid
Link to code example
Please find sample code at https://github.com/tdiluzio/react-dom-textarea-bug
Demo
Here's the URL to the demo https://tdiluzio.github.io/react-dom-textarea-bug/