Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,34 @@ export function DatePickerWithRange({
strictlyBottom,
}: React.HTMLAttributes<HTMLDivElement> & DatePickerWithRangeProps) {
function handleDayClick(date: Date) {
if (dates?.endDate) {
onDatesChange({ startDate: date, endDate: undefined });
} else {
const startDate = dates.startDate ? (date < dates.startDate ? date : dates.startDate) : date;
const endDate = dates.startDate ? (date < dates.startDate ? dates.startDate : date) : undefined;
if (!dates.startDate) {
// If no start date set it as both start and end date
onDatesChange({ startDate: date, endDate: date });
} else if (!dates.endDate) {
// If start date exists but no end date and clicked date is before start date set it as both start and end date
const startDate = date < dates.startDate ? date : dates.startDate;
const endDate = date < dates.startDate ? dates.startDate : date;
onDatesChange({ startDate, endDate });
} else {
// If both dates exist
if (date.getTime() === dates.startDate.getTime() && dates.endDate) {
// If clicking the start date again when there's a range, set it as both start and end
onDatesChange({ startDate: date, endDate: date });
} else if (date <= dates.endDate) {
Copy link
Contributor

@shawnCaza shawnCaza Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this logic we can only change the start date. We can't change the end date unless we pick a date past the current end date. Makes for a confusing UX.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @shawnCaza thx for giving more clarity I'm working on this issue

// If clicking a date before or equal to end date, keep end date and set new start
onDatesChange({ startDate: date, endDate: dates.endDate });
} else {
// If clicking after end date, start new range
onDatesChange({ startDate: date, endDate: date });
}
}
}

const fromDate = minDate ?? new Date();

const calendar = (
<Calendar
initialFocus
//When explicitly null, we want past dates to be shown as well, otherwise show only dates passed or from current date
fromDate={minDate === null ? undefined : fromDate}
toDate={maxDate}
mode="range"
Expand Down
Loading