From 220d10113dfd0e8890f155ac1ea6757b90198d95 Mon Sep 17 00:00:00 2001 From: "peer@cal.com" Date: Thu, 26 Nov 2026 13:14:32 +0000 Subject: [PATCH 1/3] fix(calendar): keep month navigation stable Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- apps/ui/public/r/calendar.json | 2 +- apps/ui/registry/default/ui/calendar.tsx | 2 ++ packages/ui/src/components/calendar.tsx | 2 ++ packages/ui/test/components/calendar.test.tsx | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 packages/ui/test/components/calendar.test.tsx diff --git a/apps/ui/public/r/calendar.json b/apps/ui/public/r/calendar.json index 955a66ce0..b305d6eca 100644 --- a/apps/ui/public/r/calendar.json +++ b/apps/ui/public/r/calendar.json @@ -9,7 +9,7 @@ "files": [ { "path": "registry/default/ui/calendar.tsx", - "content": "\"use client\";\n\nimport { type DateLib, DayPicker } from \"@daypicker/react\";\nimport {\n ChevronLeftIcon,\n ChevronRightIcon,\n ChevronsUpDownIcon,\n} from \"lucide-react\";\nimport type * as React from \"react\";\nimport { cn } from \"@/registry/default/lib/utils\";\n\nconst buttonClassNames =\n \"relative flex size-(--cell-size) text-base sm:text-sm items-center justify-center rounded-lg text-foreground not-in-data-selected:hover:bg-accent disabled:pointer-events-none disabled:opacity-64 [&_svg:not([class*='opacity-'])]:opacity-80 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0\";\n\nexport function Calendar({\n className,\n classNames,\n showOutsideDays = true,\n components: userComponents,\n mode = \"single\",\n ...props\n}: React.ComponentProps): React.ReactElement {\n const defaultClassNames = {\n button_next: buttonClassNames,\n button_previous: buttonClassNames,\n caption_label:\n \"text-base sm:text-sm font-medium flex items-center gap-2 h-full\",\n day: \"size-(--cell-size) text-sm py-px\",\n day_button: cn(\n buttonClassNames,\n \"in-data-disabled:pointer-events-none in-[.range-middle]:rounded-none in-[.range-end:not(.range-start)]:rounded-s-none in-[.range-start:not(.range-end)]:rounded-e-none in-[.range-middle]:in-data-selected:bg-accent in-data-selected:bg-primary in-[.range-middle]:in-data-selected:text-foreground in-data-disabled:text-muted-foreground/72 in-data-outside:text-muted-foreground/72 in-data-selected:in-data-outside:text-primary-foreground in-data-selected:text-primary-foreground in-data-disabled:line-through outline-none in-[[data-selected]:not(.range-middle)]:transition-[border-radius,box-shadow] focus-visible:z-1 focus-visible:ring-[3px] focus-visible:ring-ring/50\",\n ),\n dropdown: \"absolute bg-popover inset-0 opacity-0\",\n dropdown_root:\n \"relative has-focus:border-ring has-focus:ring-ring/50 has-focus:ring-[3px] border border-input shadow-xs/5 rounded-lg px-[calc(--spacing(3)-1px)] h-9 sm:h-8 [&_svg:not([class*='opacity-'])]:opacity-80 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:-me-1\",\n dropdowns:\n \"w-full flex items-center text-base sm:text-sm justify-center h-(--cell-size) gap-1.5 *:[span]:font-medium\",\n hidden: \"invisible\",\n month: \"w-full\",\n month_caption:\n \"relative mx-(--cell-size) px-1 mb-1 flex h-(--cell-size) items-center justify-center z-2\",\n months: \"relative flex flex-col sm:flex-row gap-2\",\n nav: \"absolute top-0 flex w-full justify-between z-1\",\n outside:\n \"text-muted-foreground data-selected:bg-accent/50 data-selected:text-muted-foreground\",\n range_end: \"range-end\",\n range_middle: \"range-middle\",\n range_start: \"range-start\",\n today:\n \"*:after:pointer-events-none *:after:absolute *:after:bottom-1 *:after:start-1/2 *:after:z-1 *:after:size-[3px] *:after:-translate-x-1/2 *:after:rounded-full *:after:bg-primary [&[data-selected]:not(.range-middle)>*]:after:bg-background [&[data-disabled]>*]:after:bg-foreground/30\",\n week_number:\n \"size-(--cell-size) p-0 text-xs font-medium text-muted-foreground/72\",\n weekday:\n \"size-(--cell-size) p-0 text-xs font-medium text-muted-foreground/72\",\n };\n const mergedClassNames: typeof defaultClassNames = Object.keys(\n defaultClassNames,\n ).reduce(\n (acc, key) => {\n const userClass = classNames?.[key as keyof typeof classNames];\n const baseClass =\n defaultClassNames[key as keyof typeof defaultClassNames];\n\n acc[key as keyof typeof defaultClassNames] = userClass\n ? cn(baseClass, userClass)\n : baseClass;\n\n return acc;\n },\n { ...defaultClassNames } as typeof defaultClassNames,\n );\n\n const defaultComponents = {\n Chevron: ({\n className,\n orientation,\n ...props\n }: {\n className?: string;\n orientation?: \"left\" | \"right\" | \"up\" | \"down\";\n }): React.ReactElement => {\n if (orientation === \"left\") {\n return (\n \n );\n }\n\n if (orientation === \"right\") {\n return (\n \n );\n }\n\n return (\n \n );\n },\n };\n\n const mergedComponents = {\n ...defaultComponents,\n ...userComponents,\n };\n\n const dayPickerProps = {\n className: cn(\n \"w-fit [--cell-size:--spacing(10)] sm:[--cell-size:--spacing(9)]\",\n className,\n ),\n classNames: mergedClassNames,\n components: mergedComponents,\n \"data-slot\": \"calendar\",\n formatters: {\n formatMonthDropdown: (month: Date, dateLib: DateLib) =>\n dateLib.format(month, \"LLL\"),\n } as React.ComponentProps[\"formatters\"],\n mode,\n showOutsideDays,\n ...props,\n };\n\n return (\n )}\n />\n );\n}\n", + "content": "\"use client\";\n\nimport { type DateLib, DayPicker } from \"@daypicker/react\";\nimport {\n ChevronLeftIcon,\n ChevronRightIcon,\n ChevronsUpDownIcon,\n} from \"lucide-react\";\nimport type * as React from \"react\";\nimport { cn } from \"@/registry/default/lib/utils\";\n\nconst buttonClassNames =\n \"relative flex size-(--cell-size) text-base sm:text-sm items-center justify-center rounded-lg text-foreground not-in-data-selected:hover:bg-accent disabled:pointer-events-none disabled:opacity-64 [&_svg:not([class*='opacity-'])]:opacity-80 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0\";\n\nexport function Calendar({\n className,\n classNames,\n fixedWeeks = true,\n showOutsideDays = true,\n components: userComponents,\n mode = \"single\",\n ...props\n}: React.ComponentProps): React.ReactElement {\n const defaultClassNames = {\n button_next: buttonClassNames,\n button_previous: buttonClassNames,\n caption_label:\n \"text-base sm:text-sm font-medium flex items-center gap-2 h-full\",\n day: \"size-(--cell-size) text-sm py-px\",\n day_button: cn(\n buttonClassNames,\n \"in-data-disabled:pointer-events-none in-[.range-middle]:rounded-none in-[.range-end:not(.range-start)]:rounded-s-none in-[.range-start:not(.range-end)]:rounded-e-none in-[.range-middle]:in-data-selected:bg-accent in-data-selected:bg-primary in-[.range-middle]:in-data-selected:text-foreground in-data-disabled:text-muted-foreground/72 in-data-outside:text-muted-foreground/72 in-data-selected:in-data-outside:text-primary-foreground in-data-selected:text-primary-foreground in-data-disabled:line-through outline-none in-[[data-selected]:not(.range-middle)]:transition-[border-radius,box-shadow] focus-visible:z-1 focus-visible:ring-[3px] focus-visible:ring-ring/50\",\n ),\n dropdown: \"absolute bg-popover inset-0 opacity-0\",\n dropdown_root:\n \"relative has-focus:border-ring has-focus:ring-ring/50 has-focus:ring-[3px] border border-input shadow-xs/5 rounded-lg px-[calc(--spacing(3)-1px)] h-9 sm:h-8 [&_svg:not([class*='opacity-'])]:opacity-80 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:-me-1\",\n dropdowns:\n \"w-full flex items-center text-base sm:text-sm justify-center h-(--cell-size) gap-1.5 *:[span]:font-medium\",\n hidden: \"invisible\",\n month: \"w-full\",\n month_caption:\n \"relative mx-(--cell-size) px-1 mb-1 flex h-(--cell-size) items-center justify-center z-2\",\n months: \"relative flex flex-col sm:flex-row gap-2\",\n nav: \"absolute top-0 flex w-full justify-between z-1\",\n outside:\n \"text-muted-foreground data-selected:bg-accent/50 data-selected:text-muted-foreground\",\n range_end: \"range-end\",\n range_middle: \"range-middle\",\n range_start: \"range-start\",\n today:\n \"*:after:pointer-events-none *:after:absolute *:after:bottom-1 *:after:start-1/2 *:after:z-1 *:after:size-[3px] *:after:-translate-x-1/2 *:after:rounded-full *:after:bg-primary [&[data-selected]:not(.range-middle)>*]:after:bg-background [&[data-disabled]>*]:after:bg-foreground/30\",\n week_number:\n \"size-(--cell-size) p-0 text-xs font-medium text-muted-foreground/72\",\n weekday:\n \"size-(--cell-size) p-0 text-xs font-medium text-muted-foreground/72\",\n };\n const mergedClassNames: typeof defaultClassNames = Object.keys(\n defaultClassNames,\n ).reduce(\n (acc, key) => {\n const userClass = classNames?.[key as keyof typeof classNames];\n const baseClass =\n defaultClassNames[key as keyof typeof defaultClassNames];\n\n acc[key as keyof typeof defaultClassNames] = userClass\n ? cn(baseClass, userClass)\n : baseClass;\n\n return acc;\n },\n { ...defaultClassNames } as typeof defaultClassNames,\n );\n\n const defaultComponents = {\n Chevron: ({\n className,\n orientation,\n ...props\n }: {\n className?: string;\n orientation?: \"left\" | \"right\" | \"up\" | \"down\";\n }): React.ReactElement => {\n if (orientation === \"left\") {\n return (\n \n );\n }\n\n if (orientation === \"right\") {\n return (\n \n );\n }\n\n return (\n \n );\n },\n };\n\n const mergedComponents = {\n ...defaultComponents,\n ...userComponents,\n };\n\n const dayPickerProps = {\n className: cn(\n \"w-fit [--cell-size:--spacing(10)] sm:[--cell-size:--spacing(9)]\",\n className,\n ),\n classNames: mergedClassNames,\n components: mergedComponents,\n \"data-slot\": \"calendar\",\n fixedWeeks,\n formatters: {\n formatMonthDropdown: (month: Date, dateLib: DateLib) =>\n dateLib.format(month, \"LLL\"),\n } as React.ComponentProps[\"formatters\"],\n mode,\n showOutsideDays,\n ...props,\n };\n\n return (\n )}\n />\n );\n}\n", "type": "registry:ui" } ], diff --git a/apps/ui/registry/default/ui/calendar.tsx b/apps/ui/registry/default/ui/calendar.tsx index a255edd45..c277eaa1a 100644 --- a/apps/ui/registry/default/ui/calendar.tsx +++ b/apps/ui/registry/default/ui/calendar.tsx @@ -15,6 +15,7 @@ const buttonClassNames = export function Calendar({ className, classNames, + fixedWeeks = true, showOutsideDays = true, components: userComponents, mode = "single", @@ -122,6 +123,7 @@ export function Calendar({ classNames: mergedClassNames, components: mergedComponents, "data-slot": "calendar", + fixedWeeks, formatters: { formatMonthDropdown: (month: Date, dateLib: DateLib) => dateLib.format(month, "LLL"), diff --git a/packages/ui/src/components/calendar.tsx b/packages/ui/src/components/calendar.tsx index 4678a53a6..a7cf02077 100644 --- a/packages/ui/src/components/calendar.tsx +++ b/packages/ui/src/components/calendar.tsx @@ -15,6 +15,7 @@ const buttonClassNames = export function Calendar({ className, classNames, + fixedWeeks = true, showOutsideDays = true, components: userComponents, mode = "single", @@ -122,6 +123,7 @@ export function Calendar({ classNames: mergedClassNames, components: mergedComponents, "data-slot": "calendar", + fixedWeeks, formatters: { formatMonthDropdown: (month: Date, dateLib: DateLib) => dateLib.format(month, "LLL"), diff --git a/packages/ui/test/components/calendar.test.tsx b/packages/ui/test/components/calendar.test.tsx new file mode 100644 index 000000000..ed93e6bc6 --- /dev/null +++ b/packages/ui/test/components/calendar.test.tsx @@ -0,0 +1,19 @@ +import { expect, test } from "bun:test"; +import { renderToStaticMarkup } from "react-dom/server"; +import { Calendar } from "../../src/components/calendar"; + +function countWeeks(calendar: React.ReactElement) { + const markup = renderToStaticMarkup(calendar); + return [...markup.matchAll(/ { + expect(countWeeks()).toBe(6); + expect(countWeeks()).toBe(6); +}); + +test("allows a caller to opt out of fixed weeks", () => { + expect( + countWeeks(), + ).toBe(5); +}); From 746058466a9397784b654ba19913f48c0dbebc95 Mon Sep 17 00:00:00 2001 From: "peer@cal.com" Date: Thu, 26 Nov 2026 13:17:01 +0000 Subject: [PATCH 2/3] test(calendar): cover dropdown navigation props Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- apps/ui/content/docs/components/calendar.mdx | 1 + packages/ui/test/components/calendar.test.tsx | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/apps/ui/content/docs/components/calendar.mdx b/apps/ui/content/docs/components/calendar.mdx index 8eeb7f53d..e3790e4cf 100644 --- a/apps/ui/content/docs/components/calendar.mdx +++ b/apps/ui/content/docs/components/calendar.mdx @@ -71,6 +71,7 @@ A calendar component for date selection. | `selected` | `Date \| Date[] \| DateRange` | - | The selected date(s) | | `onSelect` | `(date: Date \| Date[] \| DateRange) => void` | - | Callback when date selection changes | | `showOutsideDays` | `boolean` | `true` | Show days from adjacent months | +| `fixedWeeks` | `boolean` | `true` | Keep the calendar at six rows between months | | `startMonth` | `Date` | - | First month to show in dropdown navigation | | `endMonth` | `Date` | - | Last month to show in dropdown navigation | | `buttonVariant` | `"ghost" \| "outline" \| ...` | `"ghost"` | Button variant for navigation buttons | diff --git a/packages/ui/test/components/calendar.test.tsx b/packages/ui/test/components/calendar.test.tsx index ed93e6bc6..634adf95a 100644 --- a/packages/ui/test/components/calendar.test.tsx +++ b/packages/ui/test/components/calendar.test.tsx @@ -17,3 +17,19 @@ test("allows a caller to opt out of fixed weeks", () => { countWeeks(), ).toBe(5); }); + +test("supports native month and year dropdowns with fixed weeks", () => { + const calendar = ( + + ); + const markup = renderToStaticMarkup(calendar); + + expect(markup).toContain('aria-label="Choose the Month"'); + expect(markup).toContain('aria-label="Choose the Year"'); + expect(countWeeks(calendar)).toBe(6); +}); From bc4554b075c2da7945d78391dc3853ad2d6d1d48 Mon Sep 17 00:00:00 2001 From: "peer@cal.com" Date: Thu, 26 Nov 2026 15:38:01 +0000 Subject: [PATCH 3/3] test(calendar): remove calendar component test Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- packages/ui/test/components/calendar.test.tsx | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100644 packages/ui/test/components/calendar.test.tsx diff --git a/packages/ui/test/components/calendar.test.tsx b/packages/ui/test/components/calendar.test.tsx deleted file mode 100644 index 634adf95a..000000000 --- a/packages/ui/test/components/calendar.test.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import { expect, test } from "bun:test"; -import { renderToStaticMarkup } from "react-dom/server"; -import { Calendar } from "../../src/components/calendar"; - -function countWeeks(calendar: React.ReactElement) { - const markup = renderToStaticMarkup(calendar); - return [...markup.matchAll(/ { - expect(countWeeks()).toBe(6); - expect(countWeeks()).toBe(6); -}); - -test("allows a caller to opt out of fixed weeks", () => { - expect( - countWeeks(), - ).toBe(5); -}); - -test("supports native month and year dropdowns with fixed weeks", () => { - const calendar = ( - - ); - const markup = renderToStaticMarkup(calendar); - - expect(markup).toContain('aria-label="Choose the Month"'); - expect(markup).toContain('aria-label="Choose the Year"'); - expect(countWeeks(calendar)).toBe(6); -});