-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathTextArea.jsx.js
More file actions
126 lines (120 loc) · 4.59 KB
/
Copy pathTextArea.jsx.js
File metadata and controls
126 lines (120 loc) · 4.59 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* 文本域
* @author Brian Li
* @email lbxxlht@163.com
* @version 0.0.2.1
*/
define(function (require) {
var React = require('react');
var InputWidget = require('./mixins/InputWidget');
var InputWidgetImeFixed = require('./mixins/InputWidgetImeFixed');
var InputWidgetImeFixedForPreactIE = require('./mixins/InputWidgetImeFixedForPreactIE');
var cTools = require('./core/componentTools');
var util = require('./core/util');
var isPreactAndIE = typeof React.render === 'function' && util.getBrowserEnterprise() === 'ie';
return React.createClass({
/**
* @properties
*
* @param {Import|Properties} src\core\componentTools.js skin className style disabled
* @param {String} placeholder 文本域中无内容时显示的提示文字
* @param {Object} inputBoxStyle 输入框中字体的样式
* @param {Function} onFocus 输入框获取焦点后的回调
* @param {Function} onBlur 输入框失去焦点后的回调
* @param {Import|Properties} src\mixins\InputWidget.js
* value onChange name validations customErrorTemplates valueTemplate
*/
/**
* @fire Import src\mixins\InputWidget.js XXX onChange
*/
contextTypes: {
appSkin: React.PropTypes.string
},
// @override
mixins: isPreactAndIE ? [InputWidget, InputWidgetImeFixedForPreactIE] : [InputWidget, InputWidgetImeFixed],
// @override
getDefaultProps: function () {
return {
// base
skin: '',
className: '',
style: {},
disabled: false,
// self
placeholder: '',
inputBoxStyle: {},
// mixin
valueTemplate: ''
};
},
// @override
getInitialState: function () {
return {
hasFocus: false
};
},
/**
* 让文本域获得焦点
* @interface focus
*/
focus: function () {
this.refs.inputbox.focus();
this.setState({hasFocus: true});
},
render: function () {
var value = this.___getValue___();
value = value === undefined || value == null ? '' : (value + '');
var width = cTools.getValueFromPropsAndStyle(this.props, 'width', 400);
var height = cTools.getValueFromPropsAndStyle(this.props, 'height', 300);
width = isNaN(width) ? 400 : +width;
height = isNaN(height) ? 300 : +height;
var containerProp = cTools.containerBaseProps('textarea', this, {
style: {
width: width,
height: height
}
})
var inputProp = {
ref: 'inputbox',
disabled: this.props.disabled,
spellCheck: false,
// 其实不应该这样写,可是textarea的padding和border会导致整体尺寸变大
style: util.extend({}, this.props.inputBoxStyle, {
width: width - 22,
height: height - 22
})
};
if (isPreactAndIE) {
util.extend(inputProp, {
onCompositionStart: this.___onCompositionStart___,
onCompositionEnd: this.___onCompositionEnd___,
onKeyUp: this.___onKeyUp___,
onFocus: this.___onFocus___,
onBlur: this.___onBlur___
});
}
else {
util.extend(inputProp, {
onCompositionStart: this.___onCompositionStart___,
onCompositionEnd: this.___onCompositionEnd___,
onKeyUp: this.___onKeyUp___,
onFocus: this.___onFocus___,
onBlur: this.___onBlur___,
onInput: this.___onInput___
});
}
// 由于IE和Chrome下placeholder表现不一致,所以自己做IE下得到焦点后,placeholder会消失,chrome不会
var labelProp = {
style: {
visibility: ((value && value.length) || this.state.hasFocus) ? 'hidden' : 'visible'
}
};
return (
<div {...containerProp}>
<div {...labelProp}>{this.props.placeholder}</div>
<textarea {...inputProp}></textarea>
</div>
);
}
});
});