diff options
Diffstat (limited to 'src/module/Panel.jsx')
-rw-r--r-- | src/module/Panel.jsx | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/module/Panel.jsx b/src/module/Panel.jsx index f041158..d5e1521 100644 --- a/src/module/Panel.jsx +++ b/src/module/Panel.jsx | |||
@@ -19,7 +19,7 @@ function generateOptions(length) { | |||
19 | const Panel = React.createClass({ | 19 | const Panel = React.createClass({ |
20 | propTypes: { | 20 | propTypes: { |
21 | prefixCls: PropTypes.string, | 21 | prefixCls: PropTypes.string, |
22 | defaultValue: PropTypes.object, | 22 | value: PropTypes.object, |
23 | locale: PropTypes.object, | 23 | locale: PropTypes.object, |
24 | placeholder: PropTypes.string, | 24 | placeholder: PropTypes.string, |
25 | formatter: PropTypes.object, | 25 | formatter: PropTypes.object, |
@@ -43,13 +43,13 @@ const Panel = React.createClass({ | |||
43 | }, | 43 | }, |
44 | 44 | ||
45 | getInitialState() { | 45 | getInitialState() { |
46 | let defaultValue = this.props.defaultValue; | 46 | let value = this.props.value; |
47 | if (!defaultValue) { | 47 | if (!value) { |
48 | defaultValue = new GregorianCalendar(zhCn); | 48 | value = new GregorianCalendar(zhCn); |
49 | defaultValue.setTime(Date.now()); | 49 | value.setTime(Date.now()); |
50 | } | 50 | } |
51 | return { | 51 | return { |
52 | value: defaultValue, | 52 | value, |
53 | }; | 53 | }; |
54 | }, | 54 | }, |
55 | 55 | ||
@@ -63,6 +63,15 @@ const Panel = React.createClass({ | |||
63 | } | 63 | } |
64 | }, | 64 | }, |
65 | 65 | ||
66 | componentWillReceiveProps(nextProps) { | ||
67 | const value = nextProps.value; | ||
68 | if (value) { | ||
69 | this.setState({ | ||
70 | value, | ||
71 | }); | ||
72 | } | ||
73 | }, | ||
74 | |||
66 | onChange(newValue) { | 75 | onChange(newValue) { |
67 | this.setState({ value: newValue }); | 76 | this.setState({ value: newValue }); |
68 | this.props.onChange(newValue); | 77 | this.props.onChange(newValue); |
@@ -76,8 +85,8 @@ const Panel = React.createClass({ | |||
76 | showSecond: true, | 85 | showSecond: true, |
77 | 86 | ||
78 | render() { | 87 | render() { |
79 | const { locale, prefixCls, defaultValue, placeholder, hourOptions, minuteOptions, secondOptions } = this.props; | 88 | const { locale, prefixCls, placeholder, hourOptions, minuteOptions, secondOptions } = this.props; |
80 | const value = this.state.value || defaultValue; | 89 | const value = this.state.value; |
81 | const cls = classnames({ 'narrow': !this.showHour || !this.showSecond }); | 90 | const cls = classnames({ 'narrow': !this.showHour || !this.showSecond }); |
82 | 91 | ||
83 | return ( | 92 | return ( |