From 9f9f39e4fb8073f6f31d545c746e4c3b7ad651da Mon Sep 17 00:00:00 2001 From: yiminghe Date: Thu, 19 Nov 2015 19:57:17 +0800 Subject: fix value --- src/module/Panel.jsx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/module/Panel.jsx') 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) { const Panel = React.createClass({ propTypes: { prefixCls: PropTypes.string, - defaultValue: PropTypes.object, + value: PropTypes.object, locale: PropTypes.object, placeholder: PropTypes.string, formatter: PropTypes.object, @@ -43,13 +43,13 @@ const Panel = React.createClass({ }, getInitialState() { - let defaultValue = this.props.defaultValue; - if (!defaultValue) { - defaultValue = new GregorianCalendar(zhCn); - defaultValue.setTime(Date.now()); + let value = this.props.value; + if (!value) { + value = new GregorianCalendar(zhCn); + value.setTime(Date.now()); } return { - value: defaultValue, + value, }; }, @@ -63,6 +63,15 @@ const Panel = React.createClass({ } }, + componentWillReceiveProps(nextProps) { + const value = nextProps.value; + if (value) { + this.setState({ + value, + }); + } + }, + onChange(newValue) { this.setState({ value: newValue }); this.props.onChange(newValue); @@ -76,8 +85,8 @@ const Panel = React.createClass({ showSecond: true, render() { - const { locale, prefixCls, defaultValue, placeholder, hourOptions, minuteOptions, secondOptions } = this.props; - const value = this.state.value || defaultValue; + const { locale, prefixCls, placeholder, hourOptions, minuteOptions, secondOptions } = this.props; + const value = this.state.value; const cls = classnames({ 'narrow': !this.showHour || !this.showSecond }); return ( -- cgit v1.2.3