summaryrefslogtreecommitdiffstats
path: root/lib/TextareaAutosize.js
blob: c7a68df1da2964bd5eb8b6959f01f1c60df8cdfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'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);
    }
  },

  render() {
    return (
      <textarea {...this.props} ref='textarea'>
        {this.props.children}
      </textarea>
    );
  }

});

module.exports = TextareaAutosize;