| name | String | - | sets the name of the generated input |
| onOpen | Function({ open }) | | when TimePicker panel is opened |
| onClose | Function({ open }) | | when TimePicker panel is opened |
+| hourStep | Number | 1 | interval between hours in picker |
+| minuteStep | Number | 1 | interval between minutes in picker |
+| secondStep | Number | 1 | interval between seconds in picker |
## Test Case
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);
}
showSecond: PropTypes.bool,
onClear: PropTypes.func,
use12Hours: PropTypes.bool,
+ hourStep: PropTypes.number,
+ minuteStep: PropTypes.number,
+ secondStep: PropTypes.number,
addon: PropTypes.func,
};
prefixCls, className, placeholder, disabledHours, disabledMinutes,
disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear,
+ hourStep, minuteStep, secondStep,
} = this.props;
const {
value, currentSelectPanel,
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 (
<div className={classNames({ [`${prefixCls}-inner`]: true, [className]: !!className })}>
name: PropTypes.string,
autoComplete: PropTypes.string,
use12Hours: PropTypes.bool,
+ hourStep: PropTypes.number,
+ minuteStep: PropTypes.number,
+ secondStep: PropTypes.number,
};
static defaultProps = {
prefixCls, placeholder, disabledHours,
disabledMinutes, disabledSeconds, hideDisabledOptions,
allowEmpty, showHour, showMinute, showSecond, defaultOpenValue, clearText,
- addon, use12Hours,
+ addon, use12Hours, hourStep, minuteStep, secondStep,
} = this.props;
return (
<Panel
disabledSeconds={disabledSeconds}
hideDisabledOptions={hideDisabledOptions}
use12Hours={use12Hours}
+ hourStep={hourStep}
+ minuteStep={minuteStep}
+ secondStep={secondStep}
addon={addon}
/>
);
import async from 'async';
import moment from 'moment';
+const map = (arr, fn) => Array.prototype.map.call(arr, fn);
+
describe('Select', () => {
let container;
done();
});
});
+
+ it('shows only numbers according to step props', (done) => {
+ const picker = renderPicker({
+ hourStep: 5,
+ minuteStep: 15,
+ secondStep: 21,
+ });
+ const input = TestUtils.scryRenderedDOMComponentsWithClass(picker,
+ 'rc-time-picker-input')[0];
+ async.series([(next) => {
+ Simulate.click(input);
+ setTimeout(next, 100);
+ }, (next) => {
+ const selectors = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
+ 'rc-time-picker-panel-select');
+
+ const hourSelector = selectors[0];
+ const minuteSelector = selectors[1];
+ const secondSelector = selectors[2];
+
+ const hours = map(hourSelector.getElementsByTagName('li'), (li) => li.innerHTML);
+ expect(hours).to.eql(['00', '05', '10', '15', '20']);
+
+ const minutes = map(minuteSelector.getElementsByTagName('li'), (li) => li.innerHTML);
+ expect(minutes).to.eql(['00', '15', '30', '45']);
+
+ const seconds = map(secondSelector.getElementsByTagName('li'), (li) => li.innerHTML);
+ expect(seconds).to.eql(['00', '21', '42']);
+
+ next();
+ }], done);
+ });
});
describe('select number', () => {