| minuteStep | Number | 1 | interval between minutes in picker |
| secondStep | Number | 1 | interval between seconds in picker |
| focusOnOpen | Boolean | false | automatically focus the input when the picker opens |
+| closeOnEsc | Boolean | true | whether <kbd>esc</kbd> should close the picker |
| inputReadOnly | Boolean | false | set input to read only |
## Test Case
onKeyDown = (e) => {
const { onEsc, onKeyDown } = this.props;
- if (e.keyCode === 27) {
+ if (e.keyCode === 27 && onEsc) {
onEsc();
}
secondStep: PropTypes.number,
addon: PropTypes.func,
focusOnOpen: PropTypes.bool,
+ closeOnEsc: PropTypes.bool,
onKeyDown: PropTypes.func,
};
addon: noop,
onKeyDown: noop,
inputReadOnly: false,
+ closeOnEsc: true,
};
constructor(props) {
disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear,
focusOnOpen, onKeyDown, hourStep, minuteStep, secondStep, inputReadOnly,
+ closeOnEsc,
} = this.props;
const {
value, currentSelectPanel,
defaultOpenValue={defaultOpenValue}
value={value}
currentSelectPanel={currentSelectPanel}
- onEsc={onEsc}
+ onEsc={closeOnEsc ? onEsc : undefined}
format={format}
placeholder={placeholder}
hourOptions={hourOptions}
minuteStep: PropTypes.number,
secondStep: PropTypes.number,
focusOnOpen: PropTypes.bool,
+ closeOnEsc: PropTypes.bool,
onKeyDown: PropTypes.func,
autoFocus: PropTypes.bool,
id: PropTypes.string,
addon: noop,
use12Hours: false,
focusOnOpen: false,
+ closeOnEsc: true,
onKeyDown: noop,
};
prefixCls, placeholder, disabledHours,
disabledMinutes, disabledSeconds, hideDisabledOptions, inputReadOnly,
allowEmpty, showHour, showMinute, showSecond, defaultOpenValue, clearText,
- addon, use12Hours, focusOnOpen, onKeyDown, hourStep, minuteStep, secondStep,
+ addon, use12Hours, focusOnOpen, closeOnEsc, onKeyDown, hourStep, minuteStep, secondStep,
} = this.props;
return (
<Panel
secondStep={secondStep}
addon={addon}
focusOnOpen={focusOnOpen}
+ closeOnEsc={closeOnEsc}
onKeyDown={onKeyDown}
/>
);
});
});
- it('exit correctly', (done) => {
- const picker = renderPicker();
+ const closeOnEscSpec = (closeOnEsc) => (done) => {
+ const picker = renderPicker({ closeOnEsc });
expect(picker.state.open).not.to.be.ok();
const input = TestUtils.scryRenderedDOMComponentsWithClass(picker,
'rc-time-picker-input')[0];
});
setTimeout(next, 100);
}, (next) => {
- expect(picker.state.open).to.be(false);
+ expect(picker.state.open).to.be(!closeOnEsc);
expect((header).value).to.be('01:02:03');
expect((input).value).to.be('01:02:03');
}], () => {
done();
});
- });
+ };
+
+ it('exit correctly', closeOnEscSpec(true));
+
+ it('stays open if `closeOnEsc` is `false`', closeOnEscSpec(false));
it('focus on open', (done) => {
const picker = renderPicker({