From 63541ed7b1c9ad58348ea86c97f3e8b31830535b Mon Sep 17 00:00:00 2001 From: MG12 Date: Thu, 19 Nov 2015 08:37:41 +0800 Subject: clear input content and close select panel when click [x] on select panel --- src/TimePicker.jsx | 24 ++++++++++++++---------- src/locale/en_US.js | 3 --- src/locale/zh_CN.js | 3 --- src/module/Panel.jsx | 16 +--------------- 4 files changed, 15 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx index eb413cb..78d6de6 100644 --- a/src/TimePicker.jsx +++ b/src/TimePicker.jsx @@ -16,10 +16,11 @@ function refFn(field, component) { const Picker = React.createClass({ propTypes: { prefixCls: PropTypes.string, + inputClassName: PropTypes.string, locale: PropTypes.object, children: PropTypes.func, disabled: PropTypes.bool, - value: PropTypes.object, + defaultValue: PropTypes.object, open: PropTypes.bool, align: PropTypes.object, placement: PropTypes.any, @@ -54,9 +55,9 @@ const Picker = React.createClass({ }, componentWillReceiveProps(nextProps) { - const { value, open } = nextProps; - if (value !== undefined) { - this.setState({value}); + const { defaultValue, open } = nextProps; + if (defaultValue !== undefined) { + this.setState({value: defaultValue}); } if (open !== undefined) { this.setState({open}); @@ -64,14 +65,17 @@ const Picker = React.createClass({ }, onPanelChange(value) { - const props = this.props; this.setState({ value: value, }); - props.onChange(value); + this.props.onChange(value); }, onPanelClear() { + this.setState({ + value: '', + }); + this.setOpen(false); }, onVisibleChange(open) { @@ -84,11 +88,11 @@ const Picker = React.createClass({ }, getPanel() { - const { prefixCls, value, locale, formatter, placeholder, hourOptions, minuteOptions, secondOptions } = this.props; + const { prefixCls, defaultValue, locale, formatter, placeholder, hourOptions, minuteOptions, secondOptions } = this.props; return ( - + diff --git a/src/locale/en_US.js b/src/locale/en_US.js index 252d3d2..488725c 100644 --- a/src/locale/en_US.js +++ b/src/locale/en_US.js @@ -1,9 +1,6 @@ import enUs from 'gregorian-calendar-format/lib/locale/en_US'; export default { - placeholderHHmmss: 'HH:MM:SS', - placeholderHHmm: 'HH:MM', - placeholdermmss: 'MM:SS', clear: 'Clear', format: enUs, }; diff --git a/src/locale/zh_CN.js b/src/locale/zh_CN.js index 709cfb4..8e02a08 100644 --- a/src/locale/zh_CN.js +++ b/src/locale/zh_CN.js @@ -1,9 +1,6 @@ import zhCn from 'gregorian-calendar-format/lib/locale/zh_CN'; export default { - placeholderHHmmss: '时:分:秒', - placeholderHHmm: '时:分', - placeholdermmss: '分:秒', clear: '清除', format: zhCn, }; diff --git a/src/module/Panel.jsx b/src/module/Panel.jsx index 4220da8..f041158 100644 --- a/src/module/Panel.jsx +++ b/src/module/Panel.jsx @@ -72,20 +72,6 @@ const Panel = React.createClass({ this.props.onClear(); }, - getPlaceholder(placeholder) { - if (placeholder) { - return placeholder; - } - - const { locale } = this.props; - if (!this.showHour) { - return locale.placeholdermmss; - } else if (!this.showSecond) { - return locale.placeholderHHmm; - } - return locale.placeholderHHmmss; - }, - showHour: true, showSecond: true, @@ -102,7 +88,7 @@ const Panel = React.createClass({ locale={locale} value={value} formatter={this.getFormatter()} - placeholder={this.getPlaceholder(placeholder)} + placeholder={placeholder} hourOptions={hourOptions} minuteOptions={minuteOptions} secondOptions={secondOptions} -- cgit v1.2.3