From 20a0fece925e60c0e08347722ce7788b2ce40ff3 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Mon, 13 Nov 2017 13:23:55 +0200 Subject: [PATCH] Sync ExpandingTextarea with CSS breakpoint styles --- src/components/ExpandingTextarea/ExpandingTextarea.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/ExpandingTextarea/ExpandingTextarea.js b/src/components/ExpandingTextarea/ExpandingTextarea.js index 4fa5eb9d..6cb6f4bf 100644 --- a/src/components/ExpandingTextarea/ExpandingTextarea.js +++ b/src/components/ExpandingTextarea/ExpandingTextarea.js @@ -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 (