diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/.gitkeep | 0 | ||||
-rw-r--r-- | src/TextareaAutosize.js | 41 | ||||
-rw-r--r-- | src/index.js | 3 |
3 files changed, 44 insertions, 0 deletions
diff --git a/src/.gitkeep b/src/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/.gitkeep 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 diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..8051157 --- /dev/null +++ b/src/index.js @@ -0,0 +1,3 @@ +import TextareaAutosize from './TextareaAutosize.js'; + +export { TextareaAutosize };
\ No newline at end of file |