allowEmpty: PropTypes.bool,
defaultOpenValue: PropTypes.object,
currentSelectPanel: PropTypes.string,
+ onKeyDown: PropTypes.func,
};
constructor(props) {
}
onKeyDown = (e) => {
+ const { onEsc, onKeyDown } = this.props;
if (e.keyCode === 27) {
- this.props.onEsc();
+ onEsc();
}
+
+ onKeyDown(e);
}
onClear = () => {
minuteStep: PropTypes.number,
secondStep: PropTypes.number,
addon: PropTypes.func,
+ onKeyDown: PropTypes.func,
};
static defaultProps = {
defaultOpenValue: moment(),
use12Hours: false,
addon: noop,
+ onKeyDown: noop,
};
constructor(props) {
const {
prefixCls, className, placeholder, disabledHours, disabledMinutes,
disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
- format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear,
+ format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear, onKeyDown,
hourStep, minuteStep, secondStep,
} = this.props;
const {
onChange={this.onChange}
onClear={onClear}
allowEmpty={allowEmpty}
+ onKeyDown={onKeyDown}
/>
<Combobox
prefixCls={prefixCls}
scrollToSelected(duration) {
// move to selected item
const select = ReactDom.findDOMNode(this);
- const list = ReactDom.findDOMNode(this.refs.list);
+ const list = ReactDom.findDOMNode(this.list);
if (!list) {
return;
}
this.setState({ active: false });
}
+ saveList = (node) => {
+ this.list = node;
+ }
+
render() {
if (this.props.options.length === 0) {
return null;
onMouseEnter={this.handleMouseEnter}
onMouseLeave={this.handleMouseLeave}
>
- <ul ref="list">{this.getOptions()}</ul>
+ <ul ref={this.saveList}>{this.getOptions()}</ul>
</div>
);
}
onChange: PropTypes.func,
onOpen: PropTypes.func,
onClose: PropTypes.func,
+ onFocus: PropTypes.func,
+ onBlur: PropTypes.func,
addon: PropTypes.func,
name: PropTypes.string,
autoComplete: PropTypes.string,
hourStep: PropTypes.number,
minuteStep: PropTypes.number,
secondStep: PropTypes.number,
+ onKeyDown: PropTypes.func,
};
static defaultProps = {
onChange: noop,
onOpen: noop,
onClose: noop,
+ onFocus: noop,
+ onBlur: noop,
addon: noop,
use12Hours: false,
+ onKeyDown: noop,
};
constructor(props) {
prefixCls, placeholder, disabledHours,
disabledMinutes, disabledSeconds, hideDisabledOptions,
allowEmpty, showHour, showMinute, showSecond, defaultOpenValue, clearText,
- addon, use12Hours, hourStep, minuteStep, secondStep,
+ addon, use12Hours, onKeyDown, hourStep, minuteStep, secondStep,
} = this.props;
return (
<Panel
minuteStep={minuteStep}
secondStep={secondStep}
addon={addon}
+ 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>
});
});
});
+
+ describe('other operations', () => {
+ it('focus/blur correctly', (done) => {
+ let focus = false;
+ let blur = false;
+
+ const picker = renderPicker({
+ onFocus: () => {
+ focus = true;
+ },
+ onBlur: () => {
+ blur = true;
+ },
+ });
+ expect(picker.state.open).not.to.be.ok();
+ const input = TestUtils.scryRenderedDOMComponentsWithClass(picker,
+ 'rc-time-picker-input')[0];
+
+ async.series([(next) => {
+ Simulate.focus(input);
+ setTimeout(next, 100);
+ }, (next) => {
+ expect(picker.state.open).to.be(false);
+
+ Simulate.blur(input);
+ setTimeout(next, 100);
+ }, (next) => {
+ expect(focus).to.be(true);
+ expect(blur).to.be(true);
+
+ next();
+ }], () => {
+ done();
+ });
+ });
+ });
});