Skip to content

Commit a54ff72

Browse files
authored
feat: optimize time selector panel step precision logic (#596) (#617)
* feat: optimize time selector panel step precision logic (#596) * test: add case * chore: optimize time selector panel step precision logic * test: update snapshot * feat(type): update TS type * test: add case * fix: fix negative number error * perf: update performance * Update tests/picker.spec.tsx Co-authored-by: MadCcc <[email protected]> --------- Co-authored-by: MadCcc <[email protected]> (cherry picked from commit 9269984) # Conflicts: # src/interface.ts # tests/__snapshots__/picker.spec.tsx.snap * test: update case * test: update case * chore: remove snap * test: update case
1 parent 53d01f2 commit a54ff72

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/panels/TimePanel/TimeBody.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ function generateUnits(
2424
disabledUnits: number[] | undefined,
2525
) {
2626
const units: Unit[] = [];
27-
for (let i = start; i <= end; i += step) {
27+
const integerStep = step >= 1 ? step | 0 : 1;
28+
for (let i = start; i <= end; i += integerStep) {
2829
units.push({
2930
label: leftPad(i, 2),
3031
value: i,

tests/picker.spec.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,29 @@ describe('Picker.Basic', () => {
606606
);
607607
spy.mockRestore();
608608
});
609+
610+
// https://github.com/ant-design/ant-design/issues/40914
611+
['hour', 'minute', 'second'].forEach((unit, index) => {
612+
it(`should show integer when step is not integer (${unit})`, () => {
613+
const props = {
614+
[`${unit}Step`]: 5.5,
615+
};
616+
const wrapper = mount(<MomentPicker picker="time" {...props} />);
617+
wrapper.openPicker();
618+
619+
const column = wrapper.find('.rc-picker-time-panel-column').at(index);
620+
const cells = column.find('.rc-picker-time-panel-cell-inner');
621+
cells.forEach((cell) => {
622+
expect(Number.isInteger(Number(cell.text()))).toBeTruthy();
623+
});
624+
});
625+
});
626+
627+
it('should work when hourStep < 0', () => {
628+
const wrapper = mount(<MomentPicker picker="time" hourStep={-1} />);
629+
wrapper.openPicker();
630+
expect(wrapper.find('.rc-picker-time-panel-column').at(0).children()).toHaveLength(24);
631+
});
609632
});
610633

611634
it('pass data- & aria- & role', () => {

0 commit comments

Comments
 (0)