summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgcanti <giulio.canti@gmail.com>2015-12-19 11:01:49 +0100
committergcanti <giulio.canti@gmail.com>2015-12-19 11:01:49 +0100
commitf4c3c4005d8a53fcd727e255dc64f424f729ad90 (patch)
tree73ca7e48cce1e46dce8abcabcea9830c5e1ec858
parentbf86648eba8469ad1a7361569b437ddf10c76821 (diff)
downloadreact-autosize-textarea-f4c3c4005d8a53fcd727e255dc64f424f729ad90.zip
react-autosize-textarea-f4c3c4005d8a53fcd727e255dc64f424f729ad90.tar.gz
react-autosize-textarea-f4c3c4005d8a53fcd727e255dc64f424f729ad90.tar.bz2
support react v0.13.x
-rw-r--r--src/TextareaAutosize.js16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/TextareaAutosize.js b/src/TextareaAutosize.js
index 82b341f..a0b344a 100644
--- a/src/TextareaAutosize.js
+++ b/src/TextareaAutosize.js
@@ -17,16 +17,22 @@ const TextareaAutosize = React.createClass({
};
},
+ getTextareaDOMNode() {
+ return this.refs.textarea.nodeType === 1 ?
+ this.refs.textarea :
+ this.refs.textarea.getDOMNode();
+ },
+
componentDidMount() {
- autosize(this.refs.textarea);
+ autosize(this.getTextareaDOMNode());
if (this.props.onResize) {
- this.refs.textarea.addEventListener(RESIZED, this.props.onResize);
+ this.getTextareaDOMNode().addEventListener(RESIZED, this.props.onResize);
}
},
componentWillUnmount() {
if (this.props.onResize) {
- this.refs.textarea.removeEventListener(RESIZED, this.props.onResize);
+ this.getTextareaDOMNode().removeEventListener(RESIZED, this.props.onResize);
}
this.dispatchEvent(DESTROY);
},
@@ -34,7 +40,7 @@ const TextareaAutosize = React.createClass({
dispatchEvent(EVENT_TYPE, defer) {
const event = document.createEvent('Event');
event.initEvent(EVENT_TYPE, true, false);
- const dispatch = () => this.refs.textarea.dispatchEvent(event);
+ const dispatch = () => this.getTextareaDOMNode().dispatchEvent(event);
if (defer) {
setTimeout(dispatch);
} else {
@@ -60,7 +66,7 @@ const TextareaAutosize = React.createClass({
if (this.getValue(nextProps) !== this.getValue(this.props)) {
this.dispatchEvent(UPDATE, true);
}
- },
+ }
});