summaryrefslogtreecommitdiffstats
path: root/src/TextareaAutosize.js
diff options
context:
space:
mode:
authorFrancesco <firefelix@gmail.com>2015-06-10 14:12:03 +0200
committerFrancesco <firefelix@gmail.com>2015-06-10 14:21:06 +0200
commit393e800c8be43cef75303ac48ce8b43d535ca9f1 (patch)
tree677fc9b19acd18c322458a1652fc328c982f8c51 /src/TextareaAutosize.js
parent4ce236995fc6bce4956e8316ddb824444fcada64 (diff)
downloadreact-autosize-textarea-393e800c8be43cef75303ac48ce8b43d535ca9f1.zip
react-autosize-textarea-393e800c8be43cef75303ac48ce8b43d535ca9f1.tar.gz
react-autosize-textarea-393e800c8be43cef75303ac48ce8b43d535ca9f1.tar.bz2
refactored repo structure using web-lib-seed. Fix #1
Diffstat (limited to 'src/TextareaAutosize.js')
-rw-r--r--src/TextareaAutosize.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/TextareaAutosize.js b/src/TextareaAutosize.js
new file mode 100644
index 0000000..f4ab8ff
--- /dev/null
+++ b/src/TextareaAutosize.js
@@ -0,0 +1,41 @@
+'use strict';
+
+const React = require('react'),
+ autosize = require('autosize');
+
+const TextareaAutosize = React.createClass({
+
+ propTypes: {
+ onResize: React.PropTypes.func
+ },
+
+ getDefaultProps() {
+ return {
+ rows: 1
+ };
+ },
+
+ componentDidMount() {
+ autosize(this.refs.textarea.getDOMNode());
+ if (this.props.onResize) {
+ this.refs.textarea.getDOMNode().addEventListener('autosize:resized', this.props.onResize);
+ }
+ },
+
+ componentWillUnmount() {
+ if (this.props.onResize) {
+ this.refs.textarea.getDOMNode().removeEventListener('autosize:resized');
+ }
+ },
+
+ render() {
+ return (
+ <textarea {...this.props} ref='textarea'>
+ {this.props.children}
+ </textarea>
+ );
+ }
+
+});
+
+module.exports = TextareaAutosize; \ No newline at end of file