diff --git a/.changeset/proud-spoons-joke.md b/.changeset/proud-spoons-joke.md new file mode 100644 index 000000000..0625f9618 --- /dev/null +++ b/.changeset/proud-spoons-joke.md @@ -0,0 +1,15 @@ +--- +"flowbite-react": major +--- + +Correct date handling for minDate in month selection + +What's Changed + +- Fixed a bug where month selection wasn't respecting minDate constraints +- Month buttons are now correctly enabled/disabled based on minDate + +Impact + +- Users will see more accurate month selection behavior when minDate is set +- No breaking changes or migration steps required diff --git a/packages/ui/src/components/Datepicker/Views/Months.tsx b/packages/ui/src/components/Datepicker/Views/Months.tsx index 2faf45e37..8b51dc706 100644 --- a/packages/ui/src/components/Datepicker/Views/Months.tsx +++ b/packages/ui/src/components/Datepicker/Views/Months.tsx @@ -37,8 +37,10 @@ export const DatepickerViewsMonth: FC = ({ theme: cu
{[...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" });