Skip to content

Commit

Permalink
Merge pull request #21774 from bernhardoj/fix/21061-textinput-placeho…
Browse files Browse the repository at this point in the history
…lder-stuck

Fix text input label does not deactivate if the input is cleared programmatically
  • Loading branch information
johnmlee101 authored Jun 28, 2023
2 parents 53e4154 + ec150a8 commit 9fc9f79
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/components/TextInput/BaseTextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ class BaseTextInput extends Component {
}

// eslint-disable-next-line react/no-did-update-set-state
this.setState({value: inputValue, selection: this.props.selection});
this.setState({value: inputValue, selection: this.props.selection}, () => {
if (this.state.value) {
this.activateLabel();
} else if (!this.state.isFocused) {
this.deactivateLabel();
}
});

// In some cases, When the value prop is empty, it is not properly updated on the TextInput due to its uncontrolled nature, thus manually clearing the TextInput.
if (inputValue === '') {
this.input.clear();
}

if (inputValue) {
this.activateLabel();
} else if (!this.state.isFocused) {
this.deactivateLabel();
}
}

componentWillUnmount() {
Expand Down

0 comments on commit 9fc9f79

Please sign in to comment.