diff options
-rw-r--r-- | src/TextareaAutosize.js | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/TextareaAutosize.js b/src/TextareaAutosize.js index be7d822..4abaec7 100644 --- a/src/TextareaAutosize.js +++ b/src/TextareaAutosize.js @@ -22,14 +22,14 @@ export default class TextareaAutosize extends React.Component { }; state = { - maxHeight: null + lineHeight: null } componentDidMount() { const { onResize, maxRows } = this.props; if (typeof maxRows === 'number') { - this.updateMaxHeight(); + this.updateLineHeight(); // this trick is needed to force "autosize" to activate the scrollbar setTimeout(() => autosize(this.textarea)); @@ -58,14 +58,10 @@ export default class TextareaAutosize extends React.Component { getValue = ({ valueLink, value }) => valueLink ? valueLink.value : value; - updateMaxHeight = () => { - const { maxRows } = this.props; - + updateLineHeight = () => { this.setState({ - maxHeight: getLineHeight(this.textarea) * maxRows + lineHeight: getLineHeight(this.textarea) }); - - return true; } onChange = e => { @@ -85,10 +81,12 @@ export default class TextareaAutosize extends React.Component { getLocals = () => { const { props: { onResize, maxRows, onChange, style, innerRef, ...props }, // eslint-disable-line no-unused-vars - state: { maxHeight }, + state: { lineHeight }, saveDOMNodeRef } = this; + const maxHeight = maxRows && lineHeight ? lineHeight * maxRows : null; + return { ...props, saveDOMNodeRef, |