Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion packages/ui/src/components/Datepicker/Views/Days.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
isDateEqual,
isDateInRange,
isDateToday,
isMonthEqual,
Views,
} from "../helpers";

Expand All @@ -25,6 +26,7 @@ export interface DatepickerViewsDaysTheme {
selected: string;
disabled: string;
today: string;
outside: string;
};
};
}
Expand All @@ -46,7 +48,6 @@ export function DatepickerViewsDays() {

const weekDays = getWeekDays(language, weekStart);
const startDate = getFirstDayOfTheMonth(viewDate, weekStart);

return (
<>
<div className={theme.header.base}>
Expand All @@ -65,6 +66,7 @@ export function DatepickerViewsDays() {
const isDisabled =
!isDateInRange(currentDate, minDate, maxDate) || (filterDate && !filterDate(currentDate, Views.Days));
const isToday = isDateToday(currentDate);
const isOutOfMonth = !isMonthEqual(currentDate, viewDate)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Make isOutOfMonth year-aware.

Line 69 currently relies on isMonthEqual, which (per packages/ui/src/components/Datepicker/helpers.ts) checks only getMonth(). That can produce incorrect “outside” classification when month numbers match across different years. Also, this line is likely the Prettier warning source.

Proposed fix
-          const isOutOfMonth = !isMonthEqual(currentDate, viewDate)
+          const isOutOfMonth =
+            currentDate.getMonth() !== viewDate.getMonth() ||
+            currentDate.getFullYear() !== viewDate.getFullYear();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const isOutOfMonth = !isMonthEqual(currentDate, viewDate)
const isOutOfMonth =
currentDate.getMonth() !== viewDate.getMonth() ||
currentDate.getFullYear() !== viewDate.getFullYear();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/ui/src/components/Datepicker/Views/Days.tsx` at line 69, The
isOutOfMonth calculation uses isMonthEqual which only compares month numbers and
therefore misclassifies dates in the same month number but different years;
update the logic where isOutOfMonth is computed (variable isOutOfMonth in
Days.tsx that compares currentDate and viewDate) to compare both month and year
(e.g., replace isMonthEqual with a helper that checks getMonth() and
getFullYear(), or add a new isSameMonthAndYear helper in
packages/ui/src/components/Datepicker/helpers.ts and use it here) so dates from
the same month number but different years are correctly flagged as out-of-month.


return (
<button
Expand All @@ -73,6 +75,7 @@ export function DatepickerViewsDays() {
type="button"
className={twMerge(
theme.items.item.base,
isOutOfMonth && theme.items.item.outside,
isToday && theme.items.item.today,
isSelected && theme.items.item.selected,
isDisabled && theme.items.item.disabled,
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/components/Datepicker/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const datePickerTheme = createTheme<DatepickerTheme>({
base: "block flex-1 cursor-pointer rounded-lg border-0 text-center text-sm font-semibold leading-9 text-gray-900 hover:bg-gray-100 dark:text-white dark:hover:bg-gray-600",
selected: "bg-primary-700 text-white hover:bg-primary-600",
disabled: "text-gray-500",
outside: "opacity-40 text-gray-500",
today: "",
},
},
Expand Down
Loading