/
option.jsx
51 lines (45 loc) · 1.09 KB
/
option.jsx
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
"use strict"
import React from 'react';
import { IControl } from '../base';
/**
* @class UIOptionPicker
*/
class UIOptionPicker extends IControl {
static propTypes = {
/**
* @property {Array} options
*/
options: React.PropTypes.array.isRequired,
};
static defaultProps = {
options: [
{text: '未选择', value: undefined}
],
};
get defaultValue() {
return this.props.options[0].value;
}
componentDidUpdate(prevProps, prevState) {
const prevOptions = JSON.stringify(prevProps.options);
const currOptions = JSON.stringify(this.props.options);
if (prevOptions !== currOptions) {
const options = this.props.options[0];
this.onInputChange({
target: {
value: options.value || options.text
}
});
}
}
render() {
const newProps = this.createProps();
return (
<select {...newProps}>
{(this.props.options).map((item, index) => {
return <option key={index} value={item.value}>{item.text}</option>;
})}
</select>
);
}
}
module.exports = UIOptionPicker;