Skip to content

Commit

Permalink
Correct date handling for minDate in month selection
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhenlee committed Jan 23, 2025
1 parent bed3c41 commit e0252c7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/ui/src/components/Datepicker/Views/Months.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export const DatepickerViewsMonth: FC<DatepickerViewsMonthsProps> = ({ theme: cu
<div className={theme.items.base}>
{[...Array(12)].map((_month, index) => {
const newDate = new Date();
// setting day to 1 to avoid overflow issues
newDate.setMonth(index, 1);
// Set newDate to the last day of the month based on the provided index.
// This is necessary for enabling the month button when minDate is set (e.g., minDate = 1/23/2025).
newDate.setMonth(index + 1, 1);
newDate.setDate(newDate.getDate() - 1);
newDate.setFullYear(viewDate.getFullYear());
const month = getFormattedDate(language, newDate, { month: "short" });

Expand Down

0 comments on commit e0252c7

Please # to comment.