mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-28 12:43:11 +10:00
Use autosize to automatically expand textareas
This commit is contained in:
parent
d3cbae79a6
commit
cdbcc55e9b
1 changed files with 29 additions and 2 deletions
|
|
@ -1,9 +1,36 @@
|
|||
/* eslint-disable react/prefer-stateless-function, no-console */
|
||||
import React, { Component } from 'react';
|
||||
import autosize from 'autosize';
|
||||
|
||||
class ExpandingTextarea extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.textarea = null;
|
||||
}
|
||||
componentDidMount() {
|
||||
// Delay the autosize initialisation so that the autosize can
|
||||
// correctly calculate the height with the textarea value
|
||||
window.setTimeout(
|
||||
() => {
|
||||
autosize(this.textarea);
|
||||
},
|
||||
100
|
||||
);
|
||||
}
|
||||
componentDidUpdate() {
|
||||
autosize.update(this.textarea);
|
||||
}
|
||||
componentWillUnmount() {
|
||||
autosize.destroy(this.textarea);
|
||||
}
|
||||
render() {
|
||||
return <textarea {...this.props} />;
|
||||
return (
|
||||
<textarea
|
||||
{...this.props}
|
||||
ref={textarea => {
|
||||
this.textarea = textarea;
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue