refactor(input): move autoresize to didUpdate

It needs to be there because it also needs to be called when value is changed from outside by setting the value property
old
Simon Selg 2016-08-04 03:41:24 +02:00
parent 75487fb9a7
commit 8559c1818c
1 changed files with 9 additions and 3 deletions

View File

@ -69,14 +69,20 @@ const factory = (FontIcon) => {
}
}
componentDidUpdate (prevProps) {
const { multiline, value } = this.props;
// resize the textarea, if nessesary
if (multiline && (prevProps.value && prevProps.value.length) !== (value && value.length)) {
this.handleAutoresize();
}
}
componentWillUnmount () {
if (this.props.multiline) window.removeEventListener('resize', this.handleAutoresize);
}
handleChange = (event) => {
if (this.props.multiline) {
this.handleAutoresize();
}
if (this.props.onChange) this.props.onChange(event.target.value, event);
};