You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If value is conditionally trimmed/sliced in my onChage function, input should keep that value.
Current Behavior
Looks like the problem is in keeping value in Input's state itself. On value change, It triggers componentDidUpdate twice: first time for prop change, and second time for setState in its onChange func. In second update, prevProps.value and props.value are always equal, therefore input continues to update its value.
Possible Solution
Addition of maxLength prop could solve this, or changing whole logic of updating its value
Steps to Reproduce (for bugs)
Set prop value to value in component's state
On change, do not update state with new one
Value will continue to change
Even hardcoding value will only work initially. Afterwards it will have whatever user is typing
Issue Type
Bug Report
Component or Pattern Affected
Input
Expected Behavior
If value is conditionally trimmed/sliced in my onChage function, input should keep that value.
Current Behavior
Looks like the problem is in keeping value in Input's state itself. On value change, It triggers componentDidUpdate twice: first time for prop change, and second time for setState in its onChange func. In second update, prevProps.value and props.value are always equal, therefore input continues to update its value.
Possible Solution
Addition of maxLength prop could solve this, or changing whole logic of updating its value
Steps to Reproduce (for bugs)
onChange = (e) => {
const { value, name } = e.target;
if (value.length > 10) {
e.preventDefault();
}
else {
this.setState({ [name]: value });
}
};
render() {
return < Input name="fieldName" value={this.state.value} onChange={this.onChange} />
}
Context
I'm trying to prevent user from entering x number of characters.
Your Environment
The text was updated successfully, but these errors were encountered: