]> git.immae.eu Git - github/fretlink/time-picker.git/blobdiff - src/TimePicker.jsx
clear input content and close select panel when click [x] on select panel
[github/fretlink/time-picker.git] / src / TimePicker.jsx
index 02ed5a2d394c1df6e0665baa00844c1c64e5eaab..78d6de6f3c0d3bb99f9195b13f78e1d9f11b11fb 100644 (file)
@@ -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,16 @@ 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);
   },
 
@@ -85,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 (
       <Panel
         prefixCls={prefixCls}
-        defaultValue={value}
+        defaultValue={defaultValue}
         locale={locale}
         formatter={formatter}
         placeholder={placeholder}
@@ -130,7 +133,7 @@ const Picker = React.createClass({
   },
 
   render() {
-    const { prefixCls, placeholder, placement, align, disabled, transitionName, children, formatter } = this.props;
+    const { prefixCls, placeholder, placement, align, disabled, transitionName, children, formatter, inputClassName } = this.props;
     const { open, value } = this.state;
 
     return (
@@ -147,7 +150,7 @@ const Picker = React.createClass({
         onPopupVisibleChange={this.onVisibleChange}
       >
         <span className={`${prefixCls}-picker`}>
-          <input ref="picker" type="text" placeholder={placeholder} readOnly disabled={disabled} value={value && formatter.format(value)} />
+          <input className={inputClassName} ref="picker" type="text" placeholder={placeholder} readOnly disabled={disabled} value={value && formatter.format(value)} />
           <span className={`${prefixCls}-picker-icon`} />
         </span>
       </Trigger>