diff options
author | Francesco Cioria <firefelix@gmail.com> | 2017-06-19 17:36:12 +0200 |
---|---|---|
committer | Francesco Cioria <firefelix@gmail.com> | 2017-06-19 17:36:12 +0200 |
commit | 085b4cef90305fb7ced0e91de75ddcccb2515f40 (patch) | |
tree | 6d64fbc7caba2383de29ab690229a0920c07fe12 | |
parent | a9b1e0ae60911ef66a3128e64ec17b276d2f7aa4 (diff) | |
download | react-autosize-textarea-085b4cef90305fb7ced0e91de75ddcccb2515f40.zip react-autosize-textarea-085b4cef90305fb7ced0e91de75ddcccb2515f40.tar.gz react-autosize-textarea-085b4cef90305fb7ced0e91de75ddcccb2515f40.tar.bz2 |
store lineHeight and compute maxHeight on every render
-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, |