Sync ExpandingTextarea with CSS breakpoint styles

This commit is contained in:
Kimmo Puputti 2017-11-13 13:23:55 +02:00
parent 02dbf09791
commit 20a0fece92

View file

@ -6,20 +6,29 @@ class ExpandingTextarea extends Component {
super(props);
this.timeoutId = null;
this.textarea = null;
this.update = this.update.bind(this);
}
componentDidMount() {
// Delay the autosize initialisation so that the autosize can
// correctly calculate the height with the textarea value
this.timeoutId = window.setTimeout(() => {
autosize(this.textarea);
// Listen to resize events so autosize can pick up updated CSS
// values (like max-height) when breakpoints change.
window.addEventListener('resize', this.update);
}, 100);
}
componentDidUpdate() {
autosize.update(this.textarea);
this.update();
}
componentWillUnmount() {
autosize.destroy(this.textarea);
window.clearTimeout(this.timeoutId);
window.removeEventListener('resize', this.update);
}
update() {
autosize.update(this.textarea);
}
render() {
return (