diff options
author | MG12 <wuzhao.mail@gmail.com> | 2015-11-19 08:37:41 +0800 |
---|---|---|
committer | MG12 <wuzhao.mail@gmail.com> | 2015-11-19 08:37:41 +0800 |
commit | 63541ed7b1c9ad58348ea86c97f3e8b31830535b (patch) | |
tree | bfa03255ff614ca97210a7df7e2bb8ee7f3f74d4 /src/TimePicker.jsx | |
parent | 6c6cb0fbfc159cff7ebd1c7ef9d7f5a547e57e61 (diff) | |
download | time-picker-0.5.0.tar.gz time-picker-0.5.0.tar.zst time-picker-0.5.0.zip |
Diffstat (limited to 'src/TimePicker.jsx')
-rw-r--r-- | src/TimePicker.jsx | 24 |
1 files changed, 14 insertions, 10 deletions
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) { | |||
16 | const Picker = React.createClass({ | 16 | const Picker = React.createClass({ |
17 | propTypes: { | 17 | propTypes: { |
18 | prefixCls: PropTypes.string, | 18 | prefixCls: PropTypes.string, |
19 | inputClassName: PropTypes.string, | ||
19 | locale: PropTypes.object, | 20 | locale: PropTypes.object, |
20 | children: PropTypes.func, | 21 | children: PropTypes.func, |
21 | disabled: PropTypes.bool, | 22 | disabled: PropTypes.bool, |
22 | value: PropTypes.object, | 23 | defaultValue: PropTypes.object, |
23 | open: PropTypes.bool, | 24 | open: PropTypes.bool, |
24 | align: PropTypes.object, | 25 | align: PropTypes.object, |
25 | placement: PropTypes.any, | 26 | placement: PropTypes.any, |
@@ -54,9 +55,9 @@ const Picker = React.createClass({ | |||
54 | }, | 55 | }, |
55 | 56 | ||
56 | componentWillReceiveProps(nextProps) { | 57 | componentWillReceiveProps(nextProps) { |
57 | const { value, open } = nextProps; | 58 | const { defaultValue, open } = nextProps; |
58 | if (value !== undefined) { | 59 | if (defaultValue !== undefined) { |
59 | this.setState({value}); | 60 | this.setState({value: defaultValue}); |
60 | } | 61 | } |
61 | if (open !== undefined) { | 62 | if (open !== undefined) { |
62 | this.setState({open}); | 63 | this.setState({open}); |
@@ -64,14 +65,17 @@ const Picker = React.createClass({ | |||
64 | }, | 65 | }, |
65 | 66 | ||
66 | onPanelChange(value) { | 67 | onPanelChange(value) { |
67 | const props = this.props; | ||
68 | this.setState({ | 68 | this.setState({ |
69 | value: value, | 69 | value: value, |
70 | }); | 70 | }); |
71 | props.onChange(value); | 71 | this.props.onChange(value); |
72 | }, | 72 | }, |
73 | 73 | ||
74 | onPanelClear() { | 74 | onPanelClear() { |
75 | this.setState({ | ||
76 | value: '', | ||
77 | }); | ||
78 | this.setOpen(false); | ||
75 | }, | 79 | }, |
76 | 80 | ||
77 | onVisibleChange(open) { | 81 | onVisibleChange(open) { |
@@ -84,11 +88,11 @@ const Picker = React.createClass({ | |||
84 | }, | 88 | }, |
85 | 89 | ||
86 | getPanel() { | 90 | getPanel() { |
87 | const { prefixCls, value, locale, formatter, placeholder, hourOptions, minuteOptions, secondOptions } = this.props; | 91 | const { prefixCls, defaultValue, locale, formatter, placeholder, hourOptions, minuteOptions, secondOptions } = this.props; |
88 | return ( | 92 | return ( |
89 | <Panel | 93 | <Panel |
90 | prefixCls={prefixCls} | 94 | prefixCls={prefixCls} |
91 | defaultValue={value} | 95 | defaultValue={defaultValue} |
92 | locale={locale} | 96 | locale={locale} |
93 | formatter={formatter} | 97 | formatter={formatter} |
94 | placeholder={placeholder} | 98 | placeholder={placeholder} |
@@ -129,7 +133,7 @@ const Picker = React.createClass({ | |||
129 | }, | 133 | }, |
130 | 134 | ||
131 | render() { | 135 | render() { |
132 | const { prefixCls, placeholder, placement, align, disabled, transitionName, children, formatter } = this.props; | 136 | const { prefixCls, placeholder, placement, align, disabled, transitionName, children, formatter, inputClassName } = this.props; |
133 | const { open, value } = this.state; | 137 | const { open, value } = this.state; |
134 | 138 | ||
135 | return ( | 139 | return ( |
@@ -146,7 +150,7 @@ const Picker = React.createClass({ | |||
146 | onPopupVisibleChange={this.onVisibleChange} | 150 | onPopupVisibleChange={this.onVisibleChange} |
147 | > | 151 | > |
148 | <span className={`${prefixCls}-picker`}> | 152 | <span className={`${prefixCls}-picker`}> |
149 | <input ref="picker" type="text" placeholder={placeholder} readOnly disabled={disabled} value={value && formatter.format(value)} /> | 153 | <input className={inputClassName} ref="picker" type="text" placeholder={placeholder} readOnly disabled={disabled} value={value && formatter.format(value)} /> |
150 | <span className={`${prefixCls}-picker-icon`} /> | 154 | <span className={`${prefixCls}-picker-icon`} /> |
151 | </span> | 155 | </span> |
152 | </Trigger> | 156 | </Trigger> |