Skip to content

Commit 49554bf

Browse files
committed
🐛 Fix '--in-selecting-range' class apply condition for End Date Picker
- Updated the condition to apply the mentioned class on the other months only if the endDate is not specified Closes #5502
1 parent 386fce0 commit 49554bf

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

src/day.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ export default class Day extends Component<DayProps> {
312312
if (
313313
selectsEnd &&
314314
startDate &&
315+
!endDate &&
315316
(isAfter(selectingDate, startDate) || isEqual(selectingDate, startDate))
316317
) {
317318
return isDayInRange(day, startDate, selectingDate);

src/test/datepicker_test.test.tsx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ function goToLastMonth(container: HTMLElement) {
5656
fireEvent.click(lastMonthButton!);
5757
}
5858

59+
function goToNextMonth(container: HTMLElement) {
60+
const nextMonthButton = safeQuerySelector(
61+
container,
62+
".react-datepicker__navigation-icon--next",
63+
);
64+
fireEvent.click(nextMonthButton!);
65+
}
66+
5967
function formatDayWithZeros(day: number) {
6068
const dayString = day.toString();
6169

@@ -3109,6 +3117,65 @@ describe("DatePicker", () => {
31093117
});
31103118
});
31113119

3120+
describe("is-selecting-range", () => {
3121+
const IN_RANGE_DAY_CLASS_NAME = "react-datepicker__day--in-selecting-range";
3122+
3123+
it("should apply '--in-selecting-range' class to the days till the preselected keyboard date on navigating to the next month without selecting endDate in the endDatePicker", () => {
3124+
const preselectedDay = 5;
3125+
const startDate = new Date(`2025/02/${preselectedDay}`);
3126+
3127+
const { container } = render(
3128+
<DatePicker
3129+
inline
3130+
selectsEnd
3131+
startDate={startDate}
3132+
minDate={startDate}
3133+
/>,
3134+
);
3135+
3136+
goToNextMonth(container);
3137+
3138+
for (let i = 1; i <= preselectedDay; i++) {
3139+
const inSelectionRangeDay = safeQuerySelector(
3140+
container,
3141+
`.react-datepicker__day--00${i}`,
3142+
);
3143+
expect(
3144+
inSelectionRangeDay.classList.contains(IN_RANGE_DAY_CLASS_NAME),
3145+
).toBe(true);
3146+
}
3147+
});
3148+
3149+
it("should not apply '--in-selecting-range' class to the days till the date that matched selectedDate in the next months (endDatePicker)", () => {
3150+
const startDay = 3;
3151+
const endDay = 8;
3152+
const startDate = new Date(`2025/02/${startDay}`);
3153+
const endDate = new Date(`2025/02/${endDay}`);
3154+
3155+
const { container } = render(
3156+
<DatePicker
3157+
inline
3158+
selectsEnd
3159+
startDate={startDate}
3160+
endDate={endDate}
3161+
minDate={startDate}
3162+
/>,
3163+
);
3164+
3165+
goToNextMonth(container);
3166+
3167+
for (let i = 1; i <= endDay; i++) {
3168+
const inSelectionRangeDay = safeQuerySelector(
3169+
container,
3170+
`.react-datepicker__day--00${i}`,
3171+
);
3172+
expect(
3173+
inSelectionRangeDay.classList.contains(IN_RANGE_DAY_CLASS_NAME),
3174+
).toBe(false);
3175+
}
3176+
});
3177+
});
3178+
31123179
describe("selectsRange without inline", () => {
31133180
it("should have preSelection set to startDate upon opening", () => {
31143181
const startDate = new Date("2021-04-20 00:00:00");

src/test/day_test.test.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,15 +688,13 @@ describe("Day", () => {
688688
});
689689

690690
describe("for an end date picker", () => {
691-
it("should highlight for dates after the start date", () => {
692-
const { startDate, endDate } = createDateRange(-1, 1);
691+
it("should highlight all dates after the start date (if the endDate is not selected yet)", () => {
692+
const { startDate } = createDateRange(-1, 1);
693693

694-
// All these should highlight: today, tomorrow (endDate), the day after
695694
for (let daysFromStart = 1; daysFromStart <= 3; daysFromStart++) {
696695
const day = addDays(startDate, daysFromStart);
697696
const container = renderDay(day, {
698697
startDate,
699-
endDate,
700698
selectingDate: day,
701699
selectsEnd: true,
702700
});

0 commit comments

Comments
 (0)