Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Release v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescoCioria committed Jun 11, 2015
1 parent 3ac1168 commit 9552088
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
32 changes: 29 additions & 3 deletions lib/TextareaAutosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var React = require('react'),
autosize = require('autosize');
autosize = require('autosize'),
UPDATE = 'autosize:update',
DESTROY = 'autosize:destroy',
RESIZED = 'autosize:resized';

var TextareaAutosize = React.createClass({
displayName: 'TextareaAutosize',
Expand All @@ -21,13 +24,30 @@ var TextareaAutosize = React.createClass({
componentDidMount: function componentDidMount() {
autosize(this.refs.textarea.getDOMNode());
if (this.props.onResize) {
this.refs.textarea.getDOMNode().addEventListener('autosize:resized', this.props.onResize);
this.refs.textarea.getDOMNode().addEventListener(RESIZED, this.props.onResize);
}
},

componentWillUnmount: function componentWillUnmount() {
if (this.props.onResize) {
this.refs.textarea.getDOMNode().removeEventListener('autosize:resized');
this.refs.textarea.getDOMNode().removeEventListener(RESIZED);
}
this.dispatchEvent(DESTROY);
},

dispatchEvent: function dispatchEvent(EVENT_TYPE) {
var _this = this;

var event = document.createEvent('Event');
event.initEvent(EVENT_TYPE, true, false);
setTimeout(function () {
return _this.refs.textarea.getDOMNode().dispatchEvent(event);
});
},

getValue: function getValue(props) {
if (props) {
return props.valueLink ? props.valueLink.value : props.value;
}
},

Expand All @@ -37,6 +57,12 @@ var TextareaAutosize = React.createClass({
_extends({}, this.props, { ref: 'textarea' }),
this.props.children
);
},

componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
if (this.getValue(nextProps) !== this.getValue(this.props)) {
this.dispatchEvent(UPDATE);
}
}

});
Expand Down
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ var _TextareaAutosizeJs = require('./TextareaAutosize.js');

var _TextareaAutosizeJs2 = _interopRequireDefault(_TextareaAutosizeJs);

exports.TextareaAutosize = _TextareaAutosizeJs2['default'];
exports['default'] = _TextareaAutosizeJs2['default'];
module.exports = exports['default'];
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/buildo/react-textarea-autosize.git"
"url": "https://github.com/buildo/react-autosize-textarea.git"
},
"keywords": [
"react",
Expand All @@ -23,9 +23,9 @@
"author": "Francesco Cioria <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/buildo/react-textarea-autosize/issues"
"url": "https://github.com/buildo/react-autosize-textarea/issues"
},
"homepage": "https://github.com/buildo/react-textarea-autosize",
"homepage": "https://github.com/buildo/react-autosize-textarea",
"devDependencies": {
"babel": "^5.4.7",
"babel-eslint": "^3.1.11",
Expand Down
2 changes: 0 additions & 2 deletions src/TextareaAutosize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const React = require('react'),
autosize = require('autosize'),
UPDATE = 'autosize:update',
Expand Down
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import TextareaAutosize from './TextareaAutosize.js';

export TextareaAutosize;
export default TextareaAutosize;

0 comments on commit 9552088

Please sign in to comment.