X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FPanel.jsx;h=a1b7c77a9cdd1ae19f28b892e2bc979141dc23f1;hb=f0ac29c61df164ab3e867ef86137faa13d85a87f;hp=65832eabaabade0a522b5926d5f1c158a1ce6468;hpb=1630cc0d1942d079a80705cd000a48df9a58b355;p=github%2Ffretlink%2Ftime-picker.git diff --git a/src/Panel.jsx b/src/Panel.jsx index 65832ea..a1b7c77 100644 --- a/src/Panel.jsx +++ b/src/Panel.jsx @@ -8,9 +8,9 @@ import classNames from 'classnames'; function noop() { } -function generateOptions(length, disabledOptions, hideDisabledOptions) { +function generateOptions(length, disabledOptions, hideDisabledOptions, step = 1) { const arr = []; - for (let value = 0; value < length; value++) { + for (let value = 0; value < length; value += step) { if (!disabledOptions || disabledOptions.indexOf(value) < 0 || !hideDisabledOptions) { arr.push(value); } @@ -39,7 +39,12 @@ class Panel extends Component { showSecond: PropTypes.bool, onClear: PropTypes.func, use12Hours: PropTypes.bool, + hourStep: PropTypes.number, + minuteStep: PropTypes.number, + secondStep: PropTypes.number, addon: PropTypes.func, + focusOnOpen: PropTypes.bool, + onKeyDown: PropTypes.func, }; static defaultProps = { @@ -52,6 +57,7 @@ class Panel extends Component { defaultOpenValue: moment(), use12Hours: false, addon: noop, + onKeyDown: noop, }; constructor(props) { @@ -80,11 +86,17 @@ class Panel extends Component { this.setState({ currentSelectPanel }); } + // https://github.com/ant-design/ant-design/issues/5829 + close() { + this.props.onEsc(); + } + render() { const { prefixCls, className, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond, format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear, + focusOnOpen, onKeyDown, hourStep, minuteStep, secondStep, } = this.props; const { value, currentSelectPanel, @@ -93,9 +105,15 @@ class Panel extends Component { const disabledMinuteOptions = disabledMinutes(value ? value.hour() : null); const disabledSecondOptions = disabledSeconds(value ? value.hour() : null, value ? value.minute() : null); - const hourOptions = generateOptions(24, disabledHourOptions, hideDisabledOptions); - const minuteOptions = generateOptions(60, disabledMinuteOptions, hideDisabledOptions); - const secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions); + const hourOptions = generateOptions( + 24, disabledHourOptions, hideDisabledOptions, hourStep + ); + const minuteOptions = generateOptions( + 60, disabledMinuteOptions, hideDisabledOptions, minuteStep + ); + const secondOptions = generateOptions( + 60, disabledSecondOptions, hideDisabledOptions, secondStep + ); return (
@@ -117,6 +135,8 @@ class Panel extends Component { onChange={this.onChange} onClear={onClear} allowEmpty={allowEmpty} + focusOnOpen={focusOnOpen} + onKeyDown={onKeyDown} />