]> git.immae.eu Git - github/fretlink/time-picker.git/commitdiff
Merge branch 'master' into focus-on-open
author偏右 <afc163@gmail.com>
Sun, 22 Oct 2017 08:24:17 +0000 (16:24 +0800)
committerGitHub <noreply@github.com>
Sun, 22 Oct 2017 08:24:17 +0000 (16:24 +0800)
1  2 
src/Header.jsx
src/Panel.jsx
src/TimePicker.jsx

diff --combined src/Header.jsx
index 6bed557af2b54b1115ed920313b90e1c18a7a359,f6dd24157ae34e04fb43d66ff8e34475d4ae48c0..1520d25e3008b371efc66bebfe620d2cf5df4034
@@@ -22,7 -22,7 +22,8 @@@ class Header extends Component 
      allowEmpty: PropTypes.bool,
      defaultOpenValue: PropTypes.object,
      currentSelectPanel: PropTypes.string,
 +    focusOnOpen: PropTypes.bool,
+     onKeyDown: PropTypes.func,
    };
  
    constructor(props) {
      };
    }
  
 +  componentDidMount() {
 +    if (this.props.focusOnOpen) {
 +      // Wait one frame for the panel to be positioned before focusing
 +      const requestAnimationFrame = (window.requestAnimationFrame || window.setTimeout);
 +      requestAnimationFrame(() => {
 +        this.refs.input.focus();
 +        this.refs.input.select();
 +      });
 +    }
 +  }
 +
    componentWillReceiveProps(nextProps) {
      const { value, format } = nextProps;
      this.setState({
    }
  
    onKeyDown = (e) => {
+     const { onEsc, onKeyDown } = this.props;
      if (e.keyCode === 27) {
-       this.props.onEsc();
+       onEsc();
      }
+     onKeyDown(e);
    }
  
    onClear = () => {
diff --combined src/Panel.jsx
index deeba5207f6a023337a4c2e8d6827b0e3ef2fc0b,8a6c872e7e73784aeeace67fe3d4bca09384b57b..957c021853900ba8f416ae682d721fdef74b2e1f
@@@ -40,7 -40,7 +40,8 @@@ class Panel extends Component 
      onClear: PropTypes.func,
      use12Hours: PropTypes.bool,
      addon: PropTypes.func,
 +    focusOnOpen: PropTypes.bool,
+     onKeyDown: PropTypes.func,
    };
  
    static defaultProps = {
@@@ -53,6 -53,7 +54,7 @@@
      defaultOpenValue: moment(),
      use12Hours: false,
      addon: noop,
+     onKeyDown: noop,
    };
  
    constructor(props) {
@@@ -90,7 -91,7 +92,7 @@@
      const {
        prefixCls, className, placeholder, disabledHours, disabledMinutes,
        disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
-       format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear, focusOnOpen,
 -      format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear, onKeyDown,
++      format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear, focusOnOpen, onKeyDown,
      } = this.props;
      const {
        value, currentSelectPanel,
            onChange={this.onChange}
            onClear={onClear}
            allowEmpty={allowEmpty}
 +          focusOnOpen={focusOnOpen}
+           onKeyDown={onKeyDown}
          />
          <Combobox
            prefixCls={prefixCls}
diff --combined src/TimePicker.jsx
index e01752732dbb7e9c8b0710f0f58dc5599f1aced5,271515da4af3973ac5ed0486c3bbc1f1e8948a6d..70327d723981bf92212702153d58bd26d60d090e
@@@ -42,11 -42,13 +42,14 @@@ export default class Picker extends Com
      onChange: PropTypes.func,
      onOpen: PropTypes.func,
      onClose: PropTypes.func,
+     onFocus: PropTypes.func,
+     onBlur: PropTypes.func,
      addon: PropTypes.func,
      name: PropTypes.string,
      autoComplete: PropTypes.string,
      use12Hours: PropTypes.bool,
 +    focusOnOpen: PropTypes.bool,
+     onKeyDown: PropTypes.func,
    };
  
    static defaultProps = {
      onChange: noop,
      onOpen: noop,
      onClose: noop,
+     onFocus: noop,
+     onBlur: noop,
      addon: noop,
      use12Hours: false,
 +    focusOnOpen: false,
+     onKeyDown: noop,
    };
  
    constructor(props) {
        prefixCls, placeholder, disabledHours,
        disabledMinutes, disabledSeconds, hideDisabledOptions,
        allowEmpty, showHour, showMinute, showSecond, defaultOpenValue, clearText,
-       addon, use12Hours, focusOnOpen,
 -      addon, use12Hours, onKeyDown,
++      addon, use12Hours, focusOnOpen, onKeyDown,
      } = this.props;
      return (
        <Panel
          hideDisabledOptions={hideDisabledOptions}
          use12Hours={use12Hours}
          addon={addon}
 +        focusOnOpen={focusOnOpen}
+         onKeyDown={onKeyDown}
        />
      );
    }
      const {
        prefixCls, placeholder, placement, align,
        disabled, transitionName, style, className, getPopupContainer, name, autoComplete,
+       onFocus, onBlur,
      } = this.props;
      const { open, value } = this.state;
      const popupClassName = this.getPopupClassName();
              onKeyDown={this.onKeyDown}
              disabled={disabled} value={value && value.format(this.getFormat()) || ''}
              autoComplete={autoComplete}
+             onFocus={onFocus}
+             onBlur={onBlur}
            />
            <span className={`${prefixCls}-icon`}/>
          </span>