summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancesco Cioria <firefelix@gmail.com>2017-01-21 12:34:55 +0100
committerFrancesco Cioria <firefelix@gmail.com>2017-01-22 19:02:12 +0100
commit0c47979fb42d6dc4c520be20f0f938fd21bd4547 (patch)
tree0f6384286639507cf58dbed8002ab03e46b7b723
parent3f1ae217d545421b827115c1a2212928a7dc7649 (diff)
downloadreact-autosize-textarea-0c47979fb42d6dc4c520be20f0f938fd21bd4547.zip
react-autosize-textarea-0c47979fb42d6dc4c520be20f0f938fd21bd4547.tar.gz
react-autosize-textarea-0c47979fb42d6dc4c520be20f0f938fd21bd4547.tar.bz2
check if value exceeds maxRows in CDM too
-rw-r--r--src/TextareaAutosize.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/TextareaAutosize.js b/src/TextareaAutosize.js
index c51648c..4aaaf63 100644
--- a/src/TextareaAutosize.js
+++ b/src/TextareaAutosize.js
@@ -31,8 +31,19 @@ export default class TextareaAutosize extends React.Component {
}
componentDidMount() {
+ const { value, defaultValue, onResize } = this.props;
+
autosize(this.textarea);
- if (this.props.onResize) {
+
+ if (this.hasReachedMaxRows(value || defaultValue)) {
+ this.updateMaxHeight(value || defaultValue);
+
+ // this trick is needed to force "autosize" to activate the scrollbar
+ this.dispatchEvent(DESTROY);
+ setTimeout(() => autosize(this.textarea));
+ }
+
+ if (onResize) {
this.textarea.addEventListener(RESIZED, this.props.onResize);
}
}