19
"use strict";
20
21
var DOMPropertyOperations = require('DOMPropertyOperations');
22
+var LinkedValueMixin = require('LinkedValueMixin');
23
var ReactCompositeComponent = require('ReactCompositeComponent');
24
var ReactDOM = require('ReactDOM');
25
48
* `defaultValue` if specified, or the children content (deprecated).
49
*/
50
var ReactDOMTextarea = ReactCompositeComponent.createClass({
51
+ mixins: [LinkedValueMixin],
52
53
getInitialState: function() {
54
var defaultValue = this.props.defaultValue;
82
if (defaultValue == null) {
83
defaultValue = '';
84
}
85
+ var value = this.getValue();
86
return {
87
// We save the initial value so that `ReactNativeComponent` doesn't update
88
// `textContent` (unnecessary since we update value).
86
- initialValue: this.props.value != null ? this.props.value : defaultValue,
89
+ initialValue: value != null ? value : defaultValue,
90
value: defaultValue
91
};
92
},
99
render: function() {
100
// Clone `this.props` so we don't mutate the input.
101
var props = merge(this.props);
102
+ var value = this.getValue();
103
104
invariant(
105
props.dangerouslySetInnerHTML == null,
107
);
108
109
props.defaultValue = null;
106
- props.value =
107
- this.props.value != null ? this.props.value : this.state.value;
110
+ props.value = value != null ? value : this.state.value;
111
props.onChange = this._handleChange;
112
113
// Always set children to the same thing. In IE9, the selection range will
116
},
117
118
componentDidUpdate: function(prevProps, prevState, rootNode) {
116
- if (this.props.value != null) {
119
+ var value = this.getValue();
120
+ if (value != null) {
121
DOMPropertyOperations.setValueForProperty(
122
rootNode,
123
'value',
120
- this.props.value !== false ? '' + this.props.value : ''
124
+ value !== false ? '' + value : ''
125
);
126
}
127
},
128
129
_handleChange: function(event) {
130
var returnValue;
127
- if (this.props.onChange) {
131
+ var onChange = this.getOnChange();
132
+ if (onChange) {
133
this._isChanging = true;
129
- returnValue = this.props.onChange(event);
134
+ returnValue = onChange(event);
135
this._isChanging = false;
136
}
137
this.setState({value: event.target.value});