Skip to content

Commit 0b526ca

Browse files
schopchytsSergey Chopchyts
andauthored
[datetime] fix(DRP): right cal shows correct month when clicking shortcut (#4066)
Fixed: Incorrect selection of years on right side when clicking through years on shortcuts while contiguousCalendarMonths=false Co-authored-by: Sergey Chopchyts <[email protected]>
1 parent fac6fd4 commit 0b526ca

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/datetime/src/dateRangePicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ function getStateChange(
704704
// If the selected month isn't in either of the displayed months, then
705705
// - set the left DayPicker to be the selected month
706706
// - set the right DayPicker to +1
707-
if (nextValueStartView.isSameMonth(nextValueEndView)) {
707+
if (nextValueStartView.isSame(nextValueEndView)) {
708708
if (leftView.isSame(nextValueStartView) || rightView.isSame(nextValueStartView)) {
709709
// do nothing
710710
} else {

packages/datetime/test/dateRangePickerTests.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,24 @@ describe("<DateRangePicker>", () => {
10181018
left.assertMonthYear(Months.JANUARY, 2016);
10191019
right.assertMonthYear(Months.FEBRUARY, 2016);
10201020
});
1021+
1022+
it("custom shortcuts set the displayed dates correctly when month stays the same but not years and contiguousCalendarMonths is false", () => {
1023+
const dateRange = [new Date(2014, Months.JUNE, 1), new Date(2015, Months.JUNE, 1)] as DateRange;
1024+
const { clickShortcut, left, right } = render({
1025+
contiguousCalendarMonths: false,
1026+
initialMonth: new Date(2015, Months.JUNE, 1),
1027+
shortcuts: [{ label: "custom shortcut", dateRange }],
1028+
});
1029+
1030+
clickShortcut();
1031+
assert.isTrue(onChangeSpy.calledOnce);
1032+
left.assertMonthYear(Months.JUNE, 2014);
1033+
right.assertMonthYear(Months.JUNE, 2015);
1034+
1035+
clickShortcut();
1036+
left.assertMonthYear(Months.JUNE, 2014);
1037+
right.assertMonthYear(Months.JUNE, 2015);
1038+
});
10211039
});
10221040

10231041
describe("when uncontrolled", () => {

0 commit comments

Comments
 (0)