mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-27 19:42:11 +10:00
Sync ExpandingTextarea with CSS breakpoint styles
This commit is contained in:
parent
02dbf09791
commit
20a0fece92
1 changed files with 10 additions and 1 deletions
|
|
@ -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 (
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue