From a23230bc97cecab9088a5bfaa9611f4a8d15e148 Mon Sep 17 00:00:00 2001 From: Hunter Johnston Date: Wed, 16 Oct 2024 20:43:18 -0400 Subject: [PATCH] fix: calendars not rendering first day of next month --- .changeset/green-pumpkins-provide.md | 5 +++++ .../src/lib/internal/date-time/calendar-helpers.svelte.ts | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/green-pumpkins-provide.md diff --git a/.changeset/green-pumpkins-provide.md b/.changeset/green-pumpkins-provide.md new file mode 100644 index 000000000..c21293a00 --- /dev/null +++ b/.changeset/green-pumpkins-provide.md @@ -0,0 +1,5 @@ +--- +"bits-ui": patch +--- + +fix: bug with calendar months sometimes not rendering the first day of the month diff --git a/packages/bits-ui/src/lib/internal/date-time/calendar-helpers.svelte.ts b/packages/bits-ui/src/lib/internal/date-time/calendar-helpers.svelte.ts index 6a1ece1cd..a7f842aab 100644 --- a/packages/bits-ui/src/lib/internal/date-time/calendar-helpers.svelte.ts +++ b/packages/bits-ui/src/lib/internal/date-time/calendar-helpers.svelte.ts @@ -105,7 +105,13 @@ function createMonth(props: CreateMonthProps): Month { startFrom = dateObj.add({ months: 1 }).set({ day: 1 }); } - const extraDaysArray = Array.from({ length: extraDays }, (_, i) => { + let length = extraDays; + if (nextMonthDays.length === 0) { + length = extraDays - 1; + nextMonthDays.push(startFrom); + } + + const extraDaysArray = Array.from({ length }, (_, i) => { const incr = i + 1; return startFrom.add({ days: incr }); });