summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/TextareaAutosize.js32
-rw-r--r--lib/index.js3
-rw-r--r--package.json6
-rw-r--r--src/TextareaAutosize.js2
-rw-r--r--src/index.js3
5 files changed, 35 insertions, 11 deletions
diff --git a/lib/TextareaAutosize.js b/lib/TextareaAutosize.js
index 07d447b..822dcbc 100644
--- a/lib/TextareaAutosize.js
+++ b/lib/TextareaAutosize.js
@@ -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',
@@ -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;
}
},
@@ -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);
+ }
}
});
diff --git a/lib/index.js b/lib/index.js
index 61cd41f..3722863 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -8,4 +8,5 @@ var _TextareaAutosizeJs = require('./TextareaAutosize.js');
var _TextareaAutosizeJs2 = _interopRequireDefault(_TextareaAutosizeJs);
-exports.TextareaAutosize = _TextareaAutosizeJs2['default']; \ No newline at end of file
+exports['default'] = _TextareaAutosizeJs2['default'];
+module.exports = exports['default']; \ No newline at end of file
diff --git a/package.json b/package.json
index 278caed..fb8c173 100644
--- a/package.json
+++ b/package.json
@@ -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",
@@ -23,9 +23,9 @@
"author": "Francesco Cioria <francesco@buildo.io>",
"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",
diff --git a/src/TextareaAutosize.js b/src/TextareaAutosize.js
index 3916ee9..68ebb3c 100644
--- a/src/TextareaAutosize.js
+++ b/src/TextareaAutosize.js
@@ -1,5 +1,3 @@
-'use strict';
-
const React = require('react'),
autosize = require('autosize'),
UPDATE = 'autosize:update',
diff --git a/src/index.js b/src/index.js
index 319b9d5..8ae221e 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,3 +1,2 @@
import TextareaAutosize from './TextareaAutosize.js';
-
-export TextareaAutosize; \ No newline at end of file
+export default TextareaAutosize; \ No newline at end of file