Skip to content

Commit 160dd9f

Browse files
authored
fix: RangePicker selection switch (#48)
* fix range logic * test case
1 parent b79b0a4 commit 160dd9f

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

src/RangePicker.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,11 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
648648
updateValues(selectedValue, date, mergedActivePickerIndex),
649649
);
650650

651-
setViewDate(date, mergedActivePickerIndex);
651+
let viewDate = date;
652+
if (panelPosition === 'right') {
653+
viewDate = getClosingViewDate(viewDate, newMode as any, generateConfig, -1);
654+
}
655+
setViewDate(viewDate, mergedActivePickerIndex);
652656
}}
653657
onOk={null}
654658
onSelect={undefined}
@@ -725,12 +729,21 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
725729
},
726730
});
727731

728-
panels = (
729-
<>
730-
{direction === 'rtl' ? rightPanel : leftPanel}
731-
{direction === 'rtl' ? showDoublePanel && leftPanel : showDoublePanel && rightPanel}
732-
</>
733-
);
732+
if (direction === 'rtl') {
733+
panels = (
734+
<>
735+
{rightPanel}
736+
{showDoublePanel && leftPanel}
737+
</>
738+
);
739+
} else {
740+
panels = (
741+
<>
742+
{leftPanel}
743+
{showDoublePanel && rightPanel}
744+
</>
745+
);
746+
}
734747
} else {
735748
panels = renderPanel();
736749
}

tests/range.spec.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,28 @@ describe('Picker.Range', () => {
933933
});
934934
},
935935
);
936+
937+
// https://github.com/ant-design/ant-design/issues/22991
938+
it('click switch 1 offset', () => {
939+
const wrapper = mount(<MomentRangePicker />);
940+
wrapper.openPicker();
941+
expect(
942+
wrapper
943+
.find('.rc-picker-header-view')
944+
.first()
945+
.text(),
946+
).toEqual('Sep1990');
947+
wrapper
948+
.find('.rc-picker-header-next-btn')
949+
.last()
950+
.simulate('click');
951+
expect(
952+
wrapper
953+
.find('.rc-picker-header-view')
954+
.first()
955+
.text(),
956+
).toEqual('Oct1990');
957+
});
936958
});
937959

938960
// https://github.com/ant-design/ant-design/issues/20868

0 commit comments

Comments
 (0)