@klinking/colander 0.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/formats/date.cjs +51 -48
- package/dist/formats/date.d.cts +10 -37
- package/dist/formats/date.d.mts +10 -37
- package/dist/formats/date.mjs +6 -2
- package/dist/formats/object.cjs +51 -48
- package/dist/formats/object.d.cts +10 -37
- package/dist/formats/object.d.mts +10 -37
- package/dist/formats/object.mjs +6 -2
- package/dist/formats/plain-date-time.cjs +51 -48
- package/dist/formats/plain-date-time.d.cts +10 -37
- package/dist/formats/plain-date-time.d.mts +10 -37
- package/dist/formats/plain-date-time.mjs +6 -2
- package/dist/formats/plain-date.cjs +51 -48
- package/dist/formats/plain-date.d.cts +10 -37
- package/dist/formats/plain-date.d.mts +10 -37
- package/dist/formats/plain-date.mjs +6 -2
- package/dist/formats/plain-month-day.cjs +51 -48
- package/dist/formats/plain-month-day.d.cts +10 -37
- package/dist/formats/plain-month-day.d.mts +10 -37
- package/dist/formats/plain-month-day.mjs +6 -2
- package/dist/formats/plain-year-month.cjs +51 -48
- package/dist/formats/plain-year-month.d.cts +10 -37
- package/dist/formats/plain-year-month.d.mts +10 -37
- package/dist/formats/plain-year-month.mjs +6 -2
- package/dist/formats/zoned-date-time.cjs +51 -48
- package/dist/formats/zoned-date-time.d.cts +10 -37
- package/dist/formats/zoned-date-time.d.mts +10 -37
- package/dist/formats/zoned-date-time.mjs +6 -2
- package/dist/index.cjs +47 -48
- package/dist/index.d.cts +11 -2
- package/dist/index.d.mts +11 -2
- package/dist/index.mjs +2 -2
- package/dist/{temporal-polyfill-DU8VfleL.cjs → weeks-navigation-CtbaTTmA.cjs} +329 -567
- package/dist/{temporal-polyfill-DTx0VIX5.mjs → weeks-navigation-D5GjCwNm.mjs} +329 -561
- package/dist/{weeks-view-context-BN6qR-83.d.mts → weeks-view-context-BZeWx9N8.d.cts} +275 -258
- package/dist/{weeks-view-context-aHGgYkpt.d.cts → weeks-view-context-MVe1b-BS.d.mts} +275 -258
- package/package.json +20 -20
- package/src/calendar-context.ts +12 -5
- package/src/calendar-provider.test.tsx +18 -4
- package/src/calendar-provider.tsx +130 -35
- package/src/calendar-types.ts +21 -4
- package/src/compute-weeks-in-window.test.ts +9 -7
- package/src/context.ts +1 -1
- package/src/day-cell.tsx +92 -46
- package/src/drag-handle.tsx +23 -24
- package/src/formats/date.ts +120 -56
- package/src/formats/formats.test.ts +8 -4
- package/src/formats/object.ts +120 -56
- package/src/formats/plain-date-time.ts +120 -56
- package/src/formats/plain-date.ts +120 -56
- package/src/formats/plain-month-day.ts +120 -56
- package/src/formats/plain-year-month.ts +120 -56
- package/src/formats/zoned-date-time.ts +120 -56
- package/src/grid-header.tsx +24 -18
- package/src/grid.event-perf.test.tsx +30 -13
- package/src/grid.perf.test.tsx +97 -33
- package/src/grid.tsx +75 -43
- package/src/index.ts +16 -4
- package/src/keyboard.test.ts +110 -42
- package/src/keyboard.ts +18 -7
- package/src/month-separator.test.tsx +3 -1
- package/src/month-separator.tsx +30 -9
- package/src/month-view-context.ts +8 -3
- package/src/month-view-types.ts +14 -10
- package/src/month-view.test.tsx +687 -68
- package/src/month-view.tsx +176 -71
- package/src/navigation.tsx +77 -47
- package/src/overflow.test.ts +15 -13
- package/src/overflow.ts +10 -2
- package/src/range-preview.tsx +37 -12
- package/src/resolve-first-week.test.ts +14 -10
- package/src/resolve-first-week.ts +6 -2
- package/src/root-selection.ts +185 -101
- package/src/selected-range.tsx +47 -22
- package/src/test-temporal.ts +0 -2
- package/src/types.ts +126 -103
- package/src/utils.bench.ts +30 -6
- package/src/utils.test.ts +203 -55
- package/src/utils.ts +156 -54
- package/src/view-context.ts +4 -1
- package/src/week-number.tsx +5 -8
- package/src/weeks-grid.tsx +45 -19
- package/src/weeks-keyboard.test.ts +6 -7
- package/src/weeks-keyboard.ts +8 -3
- package/src/weeks-navigation.tsx +21 -9
- package/src/weeks-view-context.ts +8 -3
- package/src/weeks-view-state.ts +100 -33
- package/src/weeks-view-types.ts +14 -8
- package/src/weeks-view.test.tsx +127 -19
- package/src/weeks-view.tsx +30 -12
- package/src/temporal-polyfill.test.ts +0 -317
- package/src/temporal-polyfill.ts +0 -566
package/src/month-view.test.tsx
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { render, act } from "@testing-library/react";
|
|
3
|
+
import { useState } from "react";
|
|
3
4
|
// @vitest-environment jsdom
|
|
4
5
|
import { describe, it, expect, vi } from "vitest";
|
|
5
6
|
import { useCalendarStable } from "./calendar-context";
|
|
6
7
|
import { Grid } from "./grid";
|
|
7
8
|
import { MonthView } from "./month-view";
|
|
8
9
|
import { useMonthViewState } from "./month-view-context";
|
|
9
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
MonthYearString,
|
|
12
|
+
PrevMonthButton,
|
|
13
|
+
NextMonthButton,
|
|
14
|
+
} from "./navigation";
|
|
10
15
|
import type { DateRange, ValueChangeMeta, MonthData } from "./types";
|
|
11
16
|
import { useViewContext } from "./view-context";
|
|
12
17
|
|
|
@@ -32,7 +37,9 @@ const march20 = Temporal.PlainDate.from("2026-03-20");
|
|
|
32
37
|
function SetRangeTrigger({
|
|
33
38
|
onCapture,
|
|
34
39
|
}: {
|
|
35
|
-
onCapture: (
|
|
40
|
+
onCapture: (
|
|
41
|
+
setRange: (start: Temporal.PlainDate, end: Temporal.PlainDate) => void,
|
|
42
|
+
) => void;
|
|
36
43
|
}) {
|
|
37
44
|
const { setRange } = useCalendarStable();
|
|
38
45
|
onCapture(setRange);
|
|
@@ -65,7 +72,12 @@ describe("rangeMode", () => {
|
|
|
65
72
|
) => void;
|
|
66
73
|
|
|
67
74
|
function renderRangeRoot(
|
|
68
|
-
rangeMode:
|
|
75
|
+
rangeMode:
|
|
76
|
+
| "adjust-start"
|
|
77
|
+
| "adjust-end"
|
|
78
|
+
| "nearest-start"
|
|
79
|
+
| "nearest-end"
|
|
80
|
+
| "reset",
|
|
69
81
|
onValueChange: RangeChangeFn,
|
|
70
82
|
) {
|
|
71
83
|
let selectFn: (date: Temporal.PlainDate) => void = () => {};
|
|
@@ -89,7 +101,12 @@ describe("rangeMode", () => {
|
|
|
89
101
|
|
|
90
102
|
it.each<{
|
|
91
103
|
description: string;
|
|
92
|
-
action:
|
|
104
|
+
action:
|
|
105
|
+
| "adjust-start"
|
|
106
|
+
| "adjust-end"
|
|
107
|
+
| "nearest-start"
|
|
108
|
+
| "nearest-end"
|
|
109
|
+
| "reset";
|
|
93
110
|
clickDate: Temporal.PlainDate;
|
|
94
111
|
expected: { start: string; end: string };
|
|
95
112
|
}>([
|
|
@@ -143,7 +160,7 @@ describe("rangeMode", () => {
|
|
|
143
160
|
select(clickDate);
|
|
144
161
|
});
|
|
145
162
|
|
|
146
|
-
const [value] = onValueChange.mock.calls[0]
|
|
163
|
+
const [value] = onValueChange.mock.calls[0]!;
|
|
147
164
|
expect(value!.start!.toString()).toBe(expected.start);
|
|
148
165
|
expect(value!.end!.toString()).toBe(expected.end);
|
|
149
166
|
|
|
@@ -158,7 +175,7 @@ describe("rangeMode", () => {
|
|
|
158
175
|
select(march5);
|
|
159
176
|
});
|
|
160
177
|
|
|
161
|
-
const [value] = onValueChange.mock.calls[0]
|
|
178
|
+
const [value] = onValueChange.mock.calls[0]!;
|
|
162
179
|
expect(value?.start?.toString()).toBe("2026-03-05");
|
|
163
180
|
expect(value?.end?.toString()).toBe("2026-03-20");
|
|
164
181
|
|
|
@@ -173,7 +190,7 @@ describe("rangeMode", () => {
|
|
|
173
190
|
select(march25);
|
|
174
191
|
});
|
|
175
192
|
|
|
176
|
-
const [value] = onValueChange.mock.calls[0]
|
|
193
|
+
const [value] = onValueChange.mock.calls[0]!;
|
|
177
194
|
expect(value?.start?.toString()).toBe("2026-03-10");
|
|
178
195
|
expect(value?.end?.toString()).toBe("2026-03-25");
|
|
179
196
|
|
|
@@ -188,7 +205,7 @@ describe("rangeMode", () => {
|
|
|
188
205
|
select(march10);
|
|
189
206
|
});
|
|
190
207
|
|
|
191
|
-
const [value] = onValueChange.mock.calls[0]
|
|
208
|
+
const [value] = onValueChange.mock.calls[0]!;
|
|
192
209
|
expect(value!.start!.toString()).toBe("2026-03-10");
|
|
193
210
|
expect(value!.end!.toString()).toBe("2026-03-10");
|
|
194
211
|
|
|
@@ -203,7 +220,7 @@ describe("rangeMode", () => {
|
|
|
203
220
|
select(march20);
|
|
204
221
|
});
|
|
205
222
|
|
|
206
|
-
const [value] = onValueChange.mock.calls[0]
|
|
223
|
+
const [value] = onValueChange.mock.calls[0]!;
|
|
207
224
|
expect(value!.start!.toString()).toBe("2026-03-20");
|
|
208
225
|
expect(value!.end!.toString()).toBe("2026-03-20");
|
|
209
226
|
|
|
@@ -214,10 +231,17 @@ describe("rangeMode", () => {
|
|
|
214
231
|
describe("setRange normalization", () => {
|
|
215
232
|
it("sorts start and end when called in order", () => {
|
|
216
233
|
const onValueChange = vi.fn();
|
|
217
|
-
let captured: (
|
|
234
|
+
let captured: (
|
|
235
|
+
s: Temporal.PlainDate,
|
|
236
|
+
e: Temporal.PlainDate,
|
|
237
|
+
) => void = () => {};
|
|
218
238
|
|
|
219
239
|
const { unmount } = render(
|
|
220
|
-
<MonthView
|
|
240
|
+
<MonthView
|
|
241
|
+
{...defaultProps}
|
|
242
|
+
selectionMode="range"
|
|
243
|
+
onValueChange={onValueChange}
|
|
244
|
+
>
|
|
221
245
|
<SetRangeTrigger
|
|
222
246
|
onCapture={(fn) => {
|
|
223
247
|
captured = fn;
|
|
@@ -240,10 +264,17 @@ describe("setRange normalization", () => {
|
|
|
240
264
|
|
|
241
265
|
it("normalizes reversed arguments so start <= end", () => {
|
|
242
266
|
const onValueChange = vi.fn();
|
|
243
|
-
let captured: (
|
|
267
|
+
let captured: (
|
|
268
|
+
s: Temporal.PlainDate,
|
|
269
|
+
e: Temporal.PlainDate,
|
|
270
|
+
) => void = () => {};
|
|
244
271
|
|
|
245
272
|
const { unmount } = render(
|
|
246
|
-
<MonthView
|
|
273
|
+
<MonthView
|
|
274
|
+
{...defaultProps}
|
|
275
|
+
selectionMode="range"
|
|
276
|
+
onValueChange={onValueChange}
|
|
277
|
+
>
|
|
247
278
|
<SetRangeTrigger
|
|
248
279
|
onCapture={(fn) => {
|
|
249
280
|
captured = fn;
|
|
@@ -261,7 +292,9 @@ describe("setRange normalization", () => {
|
|
|
261
292
|
DateRange<"PlainDate">,
|
|
262
293
|
ValueChangeMeta<DateRange<"PlainDate"> | null>,
|
|
263
294
|
];
|
|
264
|
-
expect(
|
|
295
|
+
expect(
|
|
296
|
+
Temporal.PlainDate.compare(value.start!, value.end!),
|
|
297
|
+
).toBeLessThanOrEqual(0);
|
|
265
298
|
expect(value).toEqual({ start: march10, end: march20 });
|
|
266
299
|
|
|
267
300
|
unmount();
|
|
@@ -269,10 +302,17 @@ describe("setRange normalization", () => {
|
|
|
269
302
|
|
|
270
303
|
it("handles same date for both start and end", () => {
|
|
271
304
|
const onValueChange = vi.fn();
|
|
272
|
-
let captured: (
|
|
305
|
+
let captured: (
|
|
306
|
+
s: Temporal.PlainDate,
|
|
307
|
+
e: Temporal.PlainDate,
|
|
308
|
+
) => void = () => {};
|
|
273
309
|
|
|
274
310
|
const { unmount } = render(
|
|
275
|
-
<MonthView
|
|
311
|
+
<MonthView
|
|
312
|
+
{...defaultProps}
|
|
313
|
+
selectionMode="range"
|
|
314
|
+
onValueChange={onValueChange}
|
|
315
|
+
>
|
|
276
316
|
<SetRangeTrigger
|
|
277
317
|
onCapture={(fn) => {
|
|
278
318
|
captured = fn;
|
|
@@ -355,8 +395,8 @@ describe("numberOfMonths", () => {
|
|
|
355
395
|
);
|
|
356
396
|
|
|
357
397
|
expect(captured!.allMonths).toHaveLength(1);
|
|
358
|
-
expect(captured!.allMonths[0]
|
|
359
|
-
expect(captured!.allMonths[0]
|
|
398
|
+
expect(captured!.allMonths[0]!.year).toBe(2026);
|
|
399
|
+
expect(captured!.allMonths[0]!.month).toBe(3);
|
|
360
400
|
|
|
361
401
|
unmount();
|
|
362
402
|
});
|
|
@@ -411,13 +451,14 @@ describe("numberOfMonths", () => {
|
|
|
411
451
|
</MonthView>,
|
|
412
452
|
);
|
|
413
453
|
|
|
414
|
-
// Select June — outside visible March
|
|
454
|
+
// Select June — outside the visible [March, April] window. Minimal shift
|
|
455
|
+
// makes June the last pane, so the start moves to May ([May, June]).
|
|
415
456
|
const june15 = Temporal.PlainDate.from("2026-06-15");
|
|
416
457
|
act(() => {
|
|
417
458
|
selectFn(june15);
|
|
418
459
|
});
|
|
419
460
|
|
|
420
|
-
expect(captured!.currentMonth).toEqual({ year: 2026, month:
|
|
461
|
+
expect(captured!.currentMonth).toEqual({ year: 2026, month: 5 });
|
|
421
462
|
|
|
422
463
|
unmount();
|
|
423
464
|
});
|
|
@@ -460,7 +501,10 @@ describe("numberOfMonths", () => {
|
|
|
460
501
|
</MonthView>,
|
|
461
502
|
);
|
|
462
503
|
|
|
463
|
-
expect(captured!.allMonths.map((m) => `${m.year}-${m.month}`)).toEqual([
|
|
504
|
+
expect(captured!.allMonths.map((m) => `${m.year}-${m.month}`)).toEqual([
|
|
505
|
+
"2026-12",
|
|
506
|
+
"2027-1",
|
|
507
|
+
]);
|
|
464
508
|
|
|
465
509
|
unmount();
|
|
466
510
|
});
|
|
@@ -478,8 +522,8 @@ describe("numberOfMonths", () => {
|
|
|
478
522
|
const grids = container.querySelectorAll('[role="grid"]');
|
|
479
523
|
expect(grids).toHaveLength(2);
|
|
480
524
|
|
|
481
|
-
const labelledBy0 = grids[0]
|
|
482
|
-
const labelledBy1 = grids[1]
|
|
525
|
+
const labelledBy0 = grids[0]!.getAttribute("aria-labelledby");
|
|
526
|
+
const labelledBy1 = grids[1]!.getAttribute("aria-labelledby");
|
|
483
527
|
expect(labelledBy0).toBeTruthy();
|
|
484
528
|
expect(labelledBy1).toBeTruthy();
|
|
485
529
|
expect(labelledBy0).not.toBe(labelledBy1);
|
|
@@ -501,8 +545,8 @@ describe("numberOfMonths", () => {
|
|
|
501
545
|
);
|
|
502
546
|
|
|
503
547
|
const grids = container.querySelectorAll('[role="grid"]');
|
|
504
|
-
const grid0Dates = grids[0]
|
|
505
|
-
const grid1Dates = grids[1]
|
|
548
|
+
const grid0Dates = grids[0]!.querySelectorAll("[data-date]");
|
|
549
|
+
const grid1Dates = grids[1]!.querySelectorAll("[data-date]");
|
|
506
550
|
|
|
507
551
|
expect(grid0Dates.length).toBeGreaterThan(0);
|
|
508
552
|
expect(grid1Dates.length).toBeGreaterThan(0);
|
|
@@ -597,20 +641,25 @@ describe("numberOfMonths", () => {
|
|
|
597
641
|
// Press PageDown to move focus to April 15 — still within visible range
|
|
598
642
|
const grid = container.querySelector('[role="grid"]')!;
|
|
599
643
|
act(() => {
|
|
600
|
-
grid.dispatchEvent(
|
|
644
|
+
grid.dispatchEvent(
|
|
645
|
+
new KeyboardEvent("keydown", { key: "PageDown", bubbles: true }),
|
|
646
|
+
);
|
|
601
647
|
});
|
|
602
648
|
|
|
603
649
|
expect(captured!.focusedDate).toBe("2026-04-15");
|
|
604
650
|
// April is the second visible month, so currentMonth stays at March
|
|
605
651
|
expect(captured!.currentMonth).toEqual({ year: 2026, month: 3 });
|
|
606
652
|
|
|
607
|
-
// Press PageDown again — May is
|
|
653
|
+
// Press PageDown again — May is one month past the window, so the start
|
|
654
|
+
// shifts by the minimum to April, making May the second pane ([April, May]).
|
|
608
655
|
act(() => {
|
|
609
|
-
grid.dispatchEvent(
|
|
656
|
+
grid.dispatchEvent(
|
|
657
|
+
new KeyboardEvent("keydown", { key: "PageDown", bubbles: true }),
|
|
658
|
+
);
|
|
610
659
|
});
|
|
611
660
|
|
|
612
661
|
expect(captured!.focusedDate).toBe("2026-05-15");
|
|
613
|
-
expect(captured!.currentMonth).toEqual({ year: 2026, month:
|
|
662
|
+
expect(captured!.currentMonth).toEqual({ year: 2026, month: 4 });
|
|
614
663
|
|
|
615
664
|
unmount();
|
|
616
665
|
});
|
|
@@ -637,7 +686,9 @@ describe("numberOfMonths", () => {
|
|
|
637
686
|
// Press PageUp to move focus to March 15 — outside visible range
|
|
638
687
|
const grid = container.querySelector('[role="grid"]')!;
|
|
639
688
|
act(() => {
|
|
640
|
-
grid.dispatchEvent(
|
|
689
|
+
grid.dispatchEvent(
|
|
690
|
+
new KeyboardEvent("keydown", { key: "PageUp", bubbles: true }),
|
|
691
|
+
);
|
|
641
692
|
});
|
|
642
693
|
|
|
643
694
|
expect(captured!.focusedDate).toBe("2026-03-15");
|
|
@@ -657,14 +708,18 @@ describe("numberOfMonths", () => {
|
|
|
657
708
|
const grids = container.querySelectorAll('[role="grid"]');
|
|
658
709
|
|
|
659
710
|
// In grid 0 (March), outside-month dates should not be March dates
|
|
660
|
-
const grid0OutsideMonth = Array.from(
|
|
711
|
+
const grid0OutsideMonth = Array.from(
|
|
712
|
+
grids[0]!.querySelectorAll("[data-outside-month]"),
|
|
713
|
+
);
|
|
661
714
|
for (const el of grid0OutsideMonth) {
|
|
662
715
|
const dateStr = el.getAttribute("data-date")!;
|
|
663
716
|
expect(dateStr.startsWith("2026-03")).toBe(false);
|
|
664
717
|
}
|
|
665
718
|
|
|
666
719
|
// In grid 1 (April), outside-month dates should not be April dates
|
|
667
|
-
const grid1OutsideMonth = Array.from(
|
|
720
|
+
const grid1OutsideMonth = Array.from(
|
|
721
|
+
grids[1]!.querySelectorAll("[data-outside-month]"),
|
|
722
|
+
);
|
|
668
723
|
for (const el of grid1OutsideMonth) {
|
|
669
724
|
const dateStr = el.getAttribute("data-date")!;
|
|
670
725
|
expect(dateStr.startsWith("2026-04")).toBe(false);
|
|
@@ -706,7 +761,12 @@ describe("numberOfMonths", () => {
|
|
|
706
761
|
it("next button disabled when last visible month reaches max", () => {
|
|
707
762
|
const maxDate = Temporal.PlainDate.from("2026-05-31");
|
|
708
763
|
const { container, unmount } = render(
|
|
709
|
-
<MonthView
|
|
764
|
+
<MonthView
|
|
765
|
+
{...defaultProps}
|
|
766
|
+
defaultValue={march15}
|
|
767
|
+
numberOfMonths={3}
|
|
768
|
+
max={maxDate}
|
|
769
|
+
>
|
|
710
770
|
<NextMonthButton data-testid="next" />
|
|
711
771
|
</MonthView>,
|
|
712
772
|
);
|
|
@@ -721,7 +781,12 @@ describe("numberOfMonths", () => {
|
|
|
721
781
|
it("prev button disabled when first visible month reaches min", () => {
|
|
722
782
|
const minDate = Temporal.PlainDate.from("2026-03-01");
|
|
723
783
|
const { container, unmount } = render(
|
|
724
|
-
<MonthView
|
|
784
|
+
<MonthView
|
|
785
|
+
{...defaultProps}
|
|
786
|
+
defaultValue={march15}
|
|
787
|
+
numberOfMonths={2}
|
|
788
|
+
min={minDate}
|
|
789
|
+
>
|
|
725
790
|
<PrevMonthButton data-testid="prev" />
|
|
726
791
|
</MonthView>,
|
|
727
792
|
);
|
|
@@ -734,7 +799,9 @@ describe("numberOfMonths", () => {
|
|
|
734
799
|
});
|
|
735
800
|
|
|
736
801
|
it("clicking next shifts view by one month", () => {
|
|
737
|
-
let captured:
|
|
802
|
+
let captured:
|
|
803
|
+
| { currentMonth: { year: number; month: number } }
|
|
804
|
+
| undefined;
|
|
738
805
|
|
|
739
806
|
const { container, unmount } = render(
|
|
740
807
|
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={2}>
|
|
@@ -762,7 +829,9 @@ describe("numberOfMonths", () => {
|
|
|
762
829
|
});
|
|
763
830
|
|
|
764
831
|
it("clicking prev shifts view by one month", () => {
|
|
765
|
-
let captured:
|
|
832
|
+
let captured:
|
|
833
|
+
| { currentMonth: { year: number; month: number } }
|
|
834
|
+
| undefined;
|
|
766
835
|
|
|
767
836
|
const { container, unmount } = render(
|
|
768
837
|
<MonthView {...defaultProps} defaultValue={march15} numberOfMonths={2}>
|
|
@@ -807,14 +876,22 @@ describe("numberOfMonths", () => {
|
|
|
807
876
|
const grids = container.querySelectorAll('[role="grid"]');
|
|
808
877
|
|
|
809
878
|
// Grid 0 (March): March 25-31 should be in range
|
|
810
|
-
const grid0InRange = Array.from(
|
|
811
|
-
|
|
879
|
+
const grid0InRange = Array.from(
|
|
880
|
+
grids[0]!.querySelectorAll("[data-in-range]"),
|
|
881
|
+
);
|
|
882
|
+
const grid0InRangeDates = grid0InRange.map((el) =>
|
|
883
|
+
el.getAttribute("data-date"),
|
|
884
|
+
);
|
|
812
885
|
expect(grid0InRangeDates).toContain("2026-03-25");
|
|
813
886
|
expect(grid0InRangeDates).toContain("2026-03-31");
|
|
814
887
|
|
|
815
888
|
// Grid 1 (April): April 1-5 should be in range
|
|
816
|
-
const grid1InRange = Array.from(
|
|
817
|
-
|
|
889
|
+
const grid1InRange = Array.from(
|
|
890
|
+
grids[1]!.querySelectorAll("[data-in-range]"),
|
|
891
|
+
);
|
|
892
|
+
const grid1InRangeDates = grid1InRange.map((el) =>
|
|
893
|
+
el.getAttribute("data-date"),
|
|
894
|
+
);
|
|
818
895
|
expect(grid1InRangeDates).toContain("2026-04-01");
|
|
819
896
|
expect(grid1InRangeDates).toContain("2026-04-05");
|
|
820
897
|
|
|
@@ -840,11 +917,15 @@ describe("numberOfMonths", () => {
|
|
|
840
917
|
const grids = container.querySelectorAll('[role="grid"]');
|
|
841
918
|
|
|
842
919
|
// range-start should be in grid 0 (March 20)
|
|
843
|
-
const grid0RangeStart = grids[0]
|
|
920
|
+
const grid0RangeStart = grids[0]!.querySelector(
|
|
921
|
+
'[data-range-start][data-date="2026-03-20"]',
|
|
922
|
+
);
|
|
844
923
|
expect(grid0RangeStart).toBeTruthy();
|
|
845
924
|
|
|
846
925
|
// range-end should be in grid 1 (April 10)
|
|
847
|
-
const grid1RangeEnd = grids[1]
|
|
926
|
+
const grid1RangeEnd = grids[1]!.querySelector(
|
|
927
|
+
'[data-range-end][data-date="2026-04-10"]',
|
|
928
|
+
);
|
|
848
929
|
expect(grid1RangeEnd).toBeTruthy();
|
|
849
930
|
|
|
850
931
|
unmount();
|
|
@@ -863,10 +944,10 @@ describe("numberOfMonths", () => {
|
|
|
863
944
|
const grids = container.querySelectorAll('[role="grid"]');
|
|
864
945
|
|
|
865
946
|
// Grid state attributes reflect each grid's month
|
|
866
|
-
expect(grids[0]
|
|
867
|
-
expect(grids[0]
|
|
868
|
-
expect(grids[1]
|
|
869
|
-
expect(grids[1]
|
|
947
|
+
expect(grids[0]!.getAttribute("data-weeks-in-month")).toBeTruthy();
|
|
948
|
+
expect(grids[0]!.getAttribute("data-days-per-week")).toBe("7");
|
|
949
|
+
expect(grids[1]!.getAttribute("data-weeks-in-month")).toBeTruthy();
|
|
950
|
+
expect(grids[1]!.getAttribute("data-days-per-week")).toBe("7");
|
|
870
951
|
|
|
871
952
|
unmount();
|
|
872
953
|
});
|
|
@@ -906,7 +987,7 @@ describe("numberOfMonths", () => {
|
|
|
906
987
|
expect(grids).toHaveLength(1);
|
|
907
988
|
|
|
908
989
|
// Grid should have aria-labelledby pointing to the MonthYearString
|
|
909
|
-
const labelledBy = grids[0]
|
|
990
|
+
const labelledBy = grids[0]!.getAttribute("aria-labelledby");
|
|
910
991
|
expect(labelledBy).toBeTruthy();
|
|
911
992
|
const label = document.getElementById(labelledBy!);
|
|
912
993
|
expect(label?.textContent).toContain("March");
|
|
@@ -925,8 +1006,10 @@ describe("numberOfMonths", () => {
|
|
|
925
1006
|
const grids = container.querySelectorAll('[role="grid"]');
|
|
926
1007
|
expect(grids).toHaveLength(1);
|
|
927
1008
|
|
|
928
|
-
const dates = Array.from(grids[0]
|
|
929
|
-
const hasMarch = dates.some((el) =>
|
|
1009
|
+
const dates = Array.from(grids[0]!.querySelectorAll("[data-date]"));
|
|
1010
|
+
const hasMarch = dates.some((el) =>
|
|
1011
|
+
el.getAttribute("data-date")?.startsWith("2026-03"),
|
|
1012
|
+
);
|
|
930
1013
|
expect(hasMarch).toBe(true);
|
|
931
1014
|
|
|
932
1015
|
unmount();
|
|
@@ -958,7 +1041,7 @@ describe("numberOfMonths", () => {
|
|
|
958
1041
|
});
|
|
959
1042
|
|
|
960
1043
|
expect(onMonthChange).toHaveBeenCalledTimes(1);
|
|
961
|
-
const arg = onMonthChange.mock.calls[0][0];
|
|
1044
|
+
const arg = onMonthChange.mock.calls[0]![0];
|
|
962
1045
|
// Should report the new first visible month (April)
|
|
963
1046
|
expect(arg.month).toBe(4);
|
|
964
1047
|
expect(arg.year).toBe(2026);
|
|
@@ -996,6 +1079,332 @@ describe("numberOfMonths", () => {
|
|
|
996
1079
|
});
|
|
997
1080
|
});
|
|
998
1081
|
|
|
1082
|
+
describe("controlled month", () => {
|
|
1083
|
+
const march = Temporal.PlainYearMonth.from("2026-03");
|
|
1084
|
+
|
|
1085
|
+
it("next button fires onMonthChange and keeps the view until the parent updates", () => {
|
|
1086
|
+
const onMonthChange = vi.fn();
|
|
1087
|
+
const { container, unmount } = render(
|
|
1088
|
+
<MonthView
|
|
1089
|
+
{...defaultProps}
|
|
1090
|
+
month={march}
|
|
1091
|
+
onMonthChange={onMonthChange}
|
|
1092
|
+
>
|
|
1093
|
+
<MonthYearString data-testid="label" />
|
|
1094
|
+
<NextMonthButton data-testid="next" />
|
|
1095
|
+
</MonthView>,
|
|
1096
|
+
);
|
|
1097
|
+
|
|
1098
|
+
act(() => {
|
|
1099
|
+
container
|
|
1100
|
+
.querySelector('[data-testid="next"]')!
|
|
1101
|
+
.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
1102
|
+
});
|
|
1103
|
+
|
|
1104
|
+
expect(onMonthChange).toHaveBeenCalledTimes(1);
|
|
1105
|
+
const arg = onMonthChange.mock.calls[0]![0];
|
|
1106
|
+
expect(arg.year).toBe(2026);
|
|
1107
|
+
expect(arg.month).toBe(4);
|
|
1108
|
+
// Controlled: the view must not move on its own
|
|
1109
|
+
expect(
|
|
1110
|
+
container.querySelector('[data-testid="label"]')!.textContent,
|
|
1111
|
+
).toContain("March");
|
|
1112
|
+
|
|
1113
|
+
unmount();
|
|
1114
|
+
});
|
|
1115
|
+
|
|
1116
|
+
it("next button advances by one month with numberOfMonths > 1", () => {
|
|
1117
|
+
// Regression: the adjacent month (April) is already visible in a
|
|
1118
|
+
// [March, April] window, so notification must come from the button
|
|
1119
|
+
// itself, not the focus-sync effect (which suppresses visible months).
|
|
1120
|
+
const onMonthChange = vi.fn();
|
|
1121
|
+
const { container, unmount } = render(
|
|
1122
|
+
<MonthView
|
|
1123
|
+
{...defaultProps}
|
|
1124
|
+
month={march}
|
|
1125
|
+
numberOfMonths={2}
|
|
1126
|
+
onMonthChange={onMonthChange}
|
|
1127
|
+
>
|
|
1128
|
+
<NextMonthButton data-testid="next" />
|
|
1129
|
+
</MonthView>,
|
|
1130
|
+
);
|
|
1131
|
+
|
|
1132
|
+
act(() => {
|
|
1133
|
+
container
|
|
1134
|
+
.querySelector('[data-testid="next"]')!
|
|
1135
|
+
.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
1136
|
+
});
|
|
1137
|
+
|
|
1138
|
+
expect(onMonthChange).toHaveBeenCalledTimes(1);
|
|
1139
|
+
const arg = onMonthChange.mock.calls[0]![0];
|
|
1140
|
+
expect(arg.year).toBe(2026);
|
|
1141
|
+
expect(arg.month).toBe(4);
|
|
1142
|
+
|
|
1143
|
+
unmount();
|
|
1144
|
+
});
|
|
1145
|
+
|
|
1146
|
+
it("still fires a later keyboard crossing after a no-op button click", () => {
|
|
1147
|
+
// Regression for a value-keyed skip: focus already sits in the adjacent
|
|
1148
|
+
// (visible) month and the parent ignores the click, so the button's
|
|
1149
|
+
// focus move is a no-op. A subsequent keyboard crossing must NOT be
|
|
1150
|
+
// wrongly suppressed.
|
|
1151
|
+
const onMonthChange = vi.fn();
|
|
1152
|
+
let selectFn: (date: Temporal.PlainDate) => void = () => {};
|
|
1153
|
+
|
|
1154
|
+
const { container, unmount } = render(
|
|
1155
|
+
<MonthView
|
|
1156
|
+
{...defaultProps}
|
|
1157
|
+
month={march}
|
|
1158
|
+
defaultValue={april15}
|
|
1159
|
+
numberOfMonths={2}
|
|
1160
|
+
onMonthChange={onMonthChange}
|
|
1161
|
+
>
|
|
1162
|
+
<SelectTrigger
|
|
1163
|
+
onCapture={(fn) => {
|
|
1164
|
+
selectFn = fn;
|
|
1165
|
+
}}
|
|
1166
|
+
/>
|
|
1167
|
+
<NextMonthButton data-testid="next" />
|
|
1168
|
+
</MonthView>,
|
|
1169
|
+
);
|
|
1170
|
+
|
|
1171
|
+
// Click next: target April is already the focused/visible month and the
|
|
1172
|
+
// parent (vi.fn) ignores it → focus move is a no-op.
|
|
1173
|
+
act(() => {
|
|
1174
|
+
container
|
|
1175
|
+
.querySelector('[data-testid="next"]')!
|
|
1176
|
+
.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
1177
|
+
});
|
|
1178
|
+
expect(onMonthChange).toHaveBeenCalledTimes(1); // April, from the button
|
|
1179
|
+
|
|
1180
|
+
// Keyboard crossing into a non-visible month must still notify. With a
|
|
1181
|
+
// 2-month window starting March, focusing May shifts the start to April
|
|
1182
|
+
// (May becomes the second pane) — the minimum shift, not a jump to May.
|
|
1183
|
+
act(() => {
|
|
1184
|
+
selectFn(Temporal.PlainDate.from("2026-05-15"));
|
|
1185
|
+
});
|
|
1186
|
+
expect(onMonthChange).toHaveBeenCalledTimes(2);
|
|
1187
|
+
const arg = onMonthChange.mock.calls[1]![0];
|
|
1188
|
+
expect(arg.year).toBe(2026);
|
|
1189
|
+
expect(arg.month).toBe(4);
|
|
1190
|
+
|
|
1191
|
+
unmount();
|
|
1192
|
+
});
|
|
1193
|
+
|
|
1194
|
+
it("prev button fires onMonthChange with the preceding month", () => {
|
|
1195
|
+
const onMonthChange = vi.fn();
|
|
1196
|
+
const { container, unmount } = render(
|
|
1197
|
+
<MonthView
|
|
1198
|
+
{...defaultProps}
|
|
1199
|
+
month={march}
|
|
1200
|
+
onMonthChange={onMonthChange}
|
|
1201
|
+
>
|
|
1202
|
+
<PrevMonthButton data-testid="prev" />
|
|
1203
|
+
</MonthView>,
|
|
1204
|
+
);
|
|
1205
|
+
|
|
1206
|
+
act(() => {
|
|
1207
|
+
container
|
|
1208
|
+
.querySelector('[data-testid="prev"]')!
|
|
1209
|
+
.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
1210
|
+
});
|
|
1211
|
+
|
|
1212
|
+
expect(onMonthChange).toHaveBeenCalledTimes(1);
|
|
1213
|
+
const arg = onMonthChange.mock.calls[0]![0];
|
|
1214
|
+
expect(arg.year).toBe(2026);
|
|
1215
|
+
expect(arg.month).toBe(2);
|
|
1216
|
+
|
|
1217
|
+
unmount();
|
|
1218
|
+
});
|
|
1219
|
+
|
|
1220
|
+
it("round-trips with a stateful parent", () => {
|
|
1221
|
+
function Harness() {
|
|
1222
|
+
const [month, setMonth] = useState(march);
|
|
1223
|
+
return (
|
|
1224
|
+
<MonthView {...defaultProps} month={month} onMonthChange={setMonth}>
|
|
1225
|
+
<MonthYearString data-testid="label" />
|
|
1226
|
+
<NextMonthButton data-testid="next" />
|
|
1227
|
+
</MonthView>
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
const { container, unmount } = render(<Harness />);
|
|
1232
|
+
expect(
|
|
1233
|
+
container.querySelector('[data-testid="label"]')!.textContent,
|
|
1234
|
+
).toContain("March");
|
|
1235
|
+
|
|
1236
|
+
act(() => {
|
|
1237
|
+
container
|
|
1238
|
+
.querySelector('[data-testid="next"]')!
|
|
1239
|
+
.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
1240
|
+
});
|
|
1241
|
+
|
|
1242
|
+
expect(
|
|
1243
|
+
container.querySelector('[data-testid="label"]')!.textContent,
|
|
1244
|
+
).toContain("April");
|
|
1245
|
+
|
|
1246
|
+
unmount();
|
|
1247
|
+
});
|
|
1248
|
+
|
|
1249
|
+
it("fires onMonthChange when focus moves into a non-visible month", () => {
|
|
1250
|
+
const onMonthChange = vi.fn();
|
|
1251
|
+
let selectFn: (date: Temporal.PlainDate) => void = () => {};
|
|
1252
|
+
|
|
1253
|
+
const { unmount } = render(
|
|
1254
|
+
<MonthView
|
|
1255
|
+
{...defaultProps}
|
|
1256
|
+
month={march}
|
|
1257
|
+
onMonthChange={onMonthChange}
|
|
1258
|
+
>
|
|
1259
|
+
<SelectTrigger
|
|
1260
|
+
onCapture={(fn) => {
|
|
1261
|
+
selectFn = fn;
|
|
1262
|
+
}}
|
|
1263
|
+
/>
|
|
1264
|
+
</MonthView>,
|
|
1265
|
+
);
|
|
1266
|
+
|
|
1267
|
+
act(() => {
|
|
1268
|
+
selectFn(april15);
|
|
1269
|
+
});
|
|
1270
|
+
|
|
1271
|
+
expect(onMonthChange).toHaveBeenCalledTimes(1);
|
|
1272
|
+
const arg = onMonthChange.mock.calls[0]![0];
|
|
1273
|
+
expect(arg.year).toBe(2026);
|
|
1274
|
+
expect(arg.month).toBe(4);
|
|
1275
|
+
|
|
1276
|
+
unmount();
|
|
1277
|
+
});
|
|
1278
|
+
|
|
1279
|
+
it("does not fire when the focused month is already visible", () => {
|
|
1280
|
+
const onMonthChange = vi.fn();
|
|
1281
|
+
let selectFn: (date: Temporal.PlainDate) => void = () => {};
|
|
1282
|
+
|
|
1283
|
+
const { unmount } = render(
|
|
1284
|
+
<MonthView
|
|
1285
|
+
{...defaultProps}
|
|
1286
|
+
month={march}
|
|
1287
|
+
numberOfMonths={2}
|
|
1288
|
+
onMonthChange={onMonthChange}
|
|
1289
|
+
>
|
|
1290
|
+
<SelectTrigger
|
|
1291
|
+
onCapture={(fn) => {
|
|
1292
|
+
selectFn = fn;
|
|
1293
|
+
}}
|
|
1294
|
+
/>
|
|
1295
|
+
</MonthView>,
|
|
1296
|
+
);
|
|
1297
|
+
|
|
1298
|
+
// April is the second visible month — no notification needed
|
|
1299
|
+
act(() => {
|
|
1300
|
+
selectFn(april15);
|
|
1301
|
+
});
|
|
1302
|
+
|
|
1303
|
+
expect(onMonthChange).not.toHaveBeenCalled();
|
|
1304
|
+
|
|
1305
|
+
unmount();
|
|
1306
|
+
});
|
|
1307
|
+
|
|
1308
|
+
it("crossing past the last visible month shifts by the minimum", () => {
|
|
1309
|
+
// [March, April] + focus into May → start becomes April ([April, May]),
|
|
1310
|
+
// not a jump to May — matching the Next button and uncontrolled mode.
|
|
1311
|
+
const onMonthChange = vi.fn();
|
|
1312
|
+
let selectFn: (date: Temporal.PlainDate) => void = () => {};
|
|
1313
|
+
|
|
1314
|
+
const { unmount } = render(
|
|
1315
|
+
<MonthView
|
|
1316
|
+
{...defaultProps}
|
|
1317
|
+
month={march}
|
|
1318
|
+
numberOfMonths={2}
|
|
1319
|
+
onMonthChange={onMonthChange}
|
|
1320
|
+
>
|
|
1321
|
+
<SelectTrigger
|
|
1322
|
+
onCapture={(fn) => {
|
|
1323
|
+
selectFn = fn;
|
|
1324
|
+
}}
|
|
1325
|
+
/>
|
|
1326
|
+
</MonthView>,
|
|
1327
|
+
);
|
|
1328
|
+
|
|
1329
|
+
act(() => {
|
|
1330
|
+
selectFn(Temporal.PlainDate.from("2026-05-15"));
|
|
1331
|
+
});
|
|
1332
|
+
|
|
1333
|
+
expect(onMonthChange).toHaveBeenCalledTimes(1);
|
|
1334
|
+
const arg = onMonthChange.mock.calls[0]![0];
|
|
1335
|
+
expect(arg.year).toBe(2026);
|
|
1336
|
+
expect(arg.month).toBe(4);
|
|
1337
|
+
|
|
1338
|
+
unmount();
|
|
1339
|
+
});
|
|
1340
|
+
});
|
|
1341
|
+
|
|
1342
|
+
describe("uncontrolled multi-month focus crossing", () => {
|
|
1343
|
+
const captureWindow = (
|
|
1344
|
+
selectDate: Temporal.PlainDate,
|
|
1345
|
+
numberOfMonths: number,
|
|
1346
|
+
) => {
|
|
1347
|
+
let captured:
|
|
1348
|
+
| {
|
|
1349
|
+
allMonths: MonthData[];
|
|
1350
|
+
currentMonth: { year: number; month: number };
|
|
1351
|
+
}
|
|
1352
|
+
| undefined;
|
|
1353
|
+
let selectFn: (date: Temporal.PlainDate) => void = () => {};
|
|
1354
|
+
|
|
1355
|
+
const { unmount } = render(
|
|
1356
|
+
<MonthView
|
|
1357
|
+
{...defaultProps}
|
|
1358
|
+
defaultValue={Temporal.PlainDate.from("2026-03-15")}
|
|
1359
|
+
numberOfMonths={numberOfMonths}
|
|
1360
|
+
>
|
|
1361
|
+
<SelectTrigger
|
|
1362
|
+
onCapture={(fn) => {
|
|
1363
|
+
selectFn = fn;
|
|
1364
|
+
}}
|
|
1365
|
+
/>
|
|
1366
|
+
<MonthDataCapture
|
|
1367
|
+
onCapture={(d) => {
|
|
1368
|
+
captured = d;
|
|
1369
|
+
}}
|
|
1370
|
+
/>
|
|
1371
|
+
</MonthView>,
|
|
1372
|
+
);
|
|
1373
|
+
|
|
1374
|
+
act(() => {
|
|
1375
|
+
selectFn(selectDate);
|
|
1376
|
+
});
|
|
1377
|
+
|
|
1378
|
+
const months = captured!.allMonths.map((m) => `${m.year}-${m.month}`);
|
|
1379
|
+
unmount();
|
|
1380
|
+
return months;
|
|
1381
|
+
};
|
|
1382
|
+
|
|
1383
|
+
it("one month past the window scrolls by one (focused becomes last pane)", () => {
|
|
1384
|
+
// [March, April], focus May → [April, May], NOT [May, June].
|
|
1385
|
+
expect(captureWindow(Temporal.PlainDate.from("2026-05-10"), 2)).toEqual([
|
|
1386
|
+
"2026-4",
|
|
1387
|
+
"2026-5",
|
|
1388
|
+
]);
|
|
1389
|
+
});
|
|
1390
|
+
|
|
1391
|
+
it("two months past the window keeps focused as the last pane", () => {
|
|
1392
|
+
// [March, April], focus June → [May, June].
|
|
1393
|
+
expect(captureWindow(Temporal.PlainDate.from("2026-06-10"), 2)).toEqual([
|
|
1394
|
+
"2026-5",
|
|
1395
|
+
"2026-6",
|
|
1396
|
+
]);
|
|
1397
|
+
});
|
|
1398
|
+
|
|
1399
|
+
it("before the window makes the focused month the first pane", () => {
|
|
1400
|
+
// [March, April], focus January → [January, February].
|
|
1401
|
+
expect(captureWindow(Temporal.PlainDate.from("2026-01-10"), 2)).toEqual([
|
|
1402
|
+
"2026-1",
|
|
1403
|
+
"2026-2",
|
|
1404
|
+
]);
|
|
1405
|
+
});
|
|
1406
|
+
});
|
|
1407
|
+
|
|
999
1408
|
describe("focusedDate across months", () => {
|
|
1000
1409
|
it("preserves focusedDate when numberOfMonths increases", () => {
|
|
1001
1410
|
let captured: { focusedDate: string } | undefined;
|
|
@@ -1082,7 +1491,9 @@ describe("numberOfMonths", () => {
|
|
|
1082
1491
|
// ArrowRight → April 1, still within visible range
|
|
1083
1492
|
const grid = container.querySelector('[role="grid"]')!;
|
|
1084
1493
|
act(() => {
|
|
1085
|
-
grid.dispatchEvent(
|
|
1494
|
+
grid.dispatchEvent(
|
|
1495
|
+
new KeyboardEvent("keydown", { key: "ArrowRight", bubbles: true }),
|
|
1496
|
+
);
|
|
1086
1497
|
});
|
|
1087
1498
|
|
|
1088
1499
|
expect(captured!.focusedDate).toBe("2026-04-01");
|
|
@@ -1093,6 +1504,178 @@ describe("numberOfMonths", () => {
|
|
|
1093
1504
|
});
|
|
1094
1505
|
});
|
|
1095
1506
|
|
|
1507
|
+
describe("non-Gregorian locale (th-TH)", () => {
|
|
1508
|
+
// th-TH defaults to the Buddhist calendar (ISO year + 543). All
|
|
1509
|
+
// PlainYearMonth values the component exposes must be ISO; the locale
|
|
1510
|
+
// calendar only affects display.
|
|
1511
|
+
const thProps = { ...defaultProps, locale: "th-TH" } as const;
|
|
1512
|
+
const march15 = Temporal.PlainDate.from("2026-03-15");
|
|
1513
|
+
|
|
1514
|
+
/** Captures rootState.viewing from MonthView context. */
|
|
1515
|
+
function ViewingCapture({
|
|
1516
|
+
onCapture,
|
|
1517
|
+
}: {
|
|
1518
|
+
onCapture: (viewing: Temporal.PlainYearMonth) => void;
|
|
1519
|
+
}) {
|
|
1520
|
+
const { rootState } = useMonthViewState();
|
|
1521
|
+
onCapture(rootState.viewing as Temporal.PlainYearMonth);
|
|
1522
|
+
return null;
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
it("onMonthChange emits an ISO PlainYearMonth, not the locale calendar", () => {
|
|
1526
|
+
const onMonthChange = vi.fn();
|
|
1527
|
+
const { container, unmount } = render(
|
|
1528
|
+
<MonthView
|
|
1529
|
+
{...thProps}
|
|
1530
|
+
defaultValue={march15}
|
|
1531
|
+
onMonthChange={onMonthChange}
|
|
1532
|
+
>
|
|
1533
|
+
<NextMonthButton data-testid="next" />
|
|
1534
|
+
</MonthView>,
|
|
1535
|
+
);
|
|
1536
|
+
|
|
1537
|
+
act(() => {
|
|
1538
|
+
container
|
|
1539
|
+
.querySelector('[data-testid="next"]')!
|
|
1540
|
+
.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
1541
|
+
});
|
|
1542
|
+
|
|
1543
|
+
expect(onMonthChange).toHaveBeenCalledTimes(1);
|
|
1544
|
+
const arg = onMonthChange.mock.calls[0]![0];
|
|
1545
|
+
// ISO April 2026 — NOT Buddhist-2026 (which is ISO 1483-06).
|
|
1546
|
+
expect(arg.toString()).toBe("2026-04");
|
|
1547
|
+
expect(arg.year).toBe(2026);
|
|
1548
|
+
expect(arg.month).toBe(4);
|
|
1549
|
+
|
|
1550
|
+
unmount();
|
|
1551
|
+
});
|
|
1552
|
+
|
|
1553
|
+
it("rootState.viewing is an ISO PlainYearMonth", () => {
|
|
1554
|
+
let viewing: Temporal.PlainYearMonth | undefined;
|
|
1555
|
+
const { unmount } = render(
|
|
1556
|
+
<MonthView {...thProps} defaultValue={march15}>
|
|
1557
|
+
<ViewingCapture
|
|
1558
|
+
onCapture={(v) => {
|
|
1559
|
+
viewing = v;
|
|
1560
|
+
}}
|
|
1561
|
+
/>
|
|
1562
|
+
</MonthView>,
|
|
1563
|
+
);
|
|
1564
|
+
|
|
1565
|
+
expect(viewing!.toString()).toBe("2026-03");
|
|
1566
|
+
|
|
1567
|
+
unmount();
|
|
1568
|
+
});
|
|
1569
|
+
|
|
1570
|
+
it("NavButtonState.target is an ISO PlainYearMonth", () => {
|
|
1571
|
+
let nextTarget: Temporal.PlainYearMonth | undefined;
|
|
1572
|
+
const { unmount } = render(
|
|
1573
|
+
<MonthView {...thProps} defaultValue={march15}>
|
|
1574
|
+
<NextMonthButton
|
|
1575
|
+
render={(props, state) => {
|
|
1576
|
+
nextTarget = state.target;
|
|
1577
|
+
return <button {...props} />;
|
|
1578
|
+
}}
|
|
1579
|
+
/>
|
|
1580
|
+
</MonthView>,
|
|
1581
|
+
);
|
|
1582
|
+
|
|
1583
|
+
// Next from ISO March 2026 → ISO April 2026, not Buddhist.
|
|
1584
|
+
expect(nextTarget!.toString()).toBe("2026-04");
|
|
1585
|
+
|
|
1586
|
+
unmount();
|
|
1587
|
+
});
|
|
1588
|
+
|
|
1589
|
+
it("still renders the month label in the locale calendar", () => {
|
|
1590
|
+
const { container, unmount } = render(
|
|
1591
|
+
<MonthView {...thProps} defaultValue={march15}>
|
|
1592
|
+
<MonthYearString data-testid="label" />
|
|
1593
|
+
</MonthView>,
|
|
1594
|
+
);
|
|
1595
|
+
|
|
1596
|
+
// ISO 2026 → Buddhist Era 2569.
|
|
1597
|
+
expect(
|
|
1598
|
+
container.querySelector('[data-testid="label"]')!.textContent,
|
|
1599
|
+
).toContain("2569");
|
|
1600
|
+
|
|
1601
|
+
unmount();
|
|
1602
|
+
});
|
|
1603
|
+
|
|
1604
|
+
it("controlled round-trips without a century jump", () => {
|
|
1605
|
+
function Harness() {
|
|
1606
|
+
const [month, setMonth] = useState(
|
|
1607
|
+
Temporal.PlainYearMonth.from("2026-03"),
|
|
1608
|
+
);
|
|
1609
|
+
return (
|
|
1610
|
+
<MonthView {...thProps} month={month} onMonthChange={setMonth}>
|
|
1611
|
+
<MonthYearString data-testid="label" />
|
|
1612
|
+
<NextMonthButton data-testid="next" />
|
|
1613
|
+
</MonthView>
|
|
1614
|
+
);
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
const { container, unmount } = render(<Harness />);
|
|
1618
|
+
const label = () =>
|
|
1619
|
+
container.querySelector('[data-testid="label"]')!.textContent ?? "";
|
|
1620
|
+
expect(label()).toContain("2569"); // March 2569 BE
|
|
1621
|
+
|
|
1622
|
+
act(() => {
|
|
1623
|
+
container
|
|
1624
|
+
.querySelector('[data-testid="next"]')!
|
|
1625
|
+
.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
1626
|
+
});
|
|
1627
|
+
|
|
1628
|
+
// Advanced one month, still Buddhist 2569 — not jumped ~543 years.
|
|
1629
|
+
expect(label()).toContain("2569");
|
|
1630
|
+
expect(label()).not.toContain("3112");
|
|
1631
|
+
|
|
1632
|
+
unmount();
|
|
1633
|
+
});
|
|
1634
|
+
});
|
|
1635
|
+
|
|
1636
|
+
describe("rootState values", () => {
|
|
1637
|
+
function RootStateCapture({
|
|
1638
|
+
onCapture,
|
|
1639
|
+
}: {
|
|
1640
|
+
onCapture: (
|
|
1641
|
+
root: ReturnType<typeof useMonthViewState>["rootState"],
|
|
1642
|
+
) => void;
|
|
1643
|
+
}) {
|
|
1644
|
+
const { rootState } = useMonthViewState();
|
|
1645
|
+
onCapture(rootState);
|
|
1646
|
+
return null;
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
it("exposes the selection as Temporal.PlainDate even when format is Date", () => {
|
|
1650
|
+
let root: ReturnType<typeof useMonthViewState>["rootState"] | undefined;
|
|
1651
|
+
const { unmount } = render(
|
|
1652
|
+
// format="Date" → defaultValue is a native Date; rootState must still
|
|
1653
|
+
// expose Temporal.PlainDate. Pre-fix `selected` was the format value (a
|
|
1654
|
+
// JS Date here), and selectedDates were PlainDate behind an `as any`.
|
|
1655
|
+
<MonthView
|
|
1656
|
+
{...defaultProps}
|
|
1657
|
+
format="Date"
|
|
1658
|
+
defaultValue={new Date(2026, 2, 10)}
|
|
1659
|
+
>
|
|
1660
|
+
<RootStateCapture
|
|
1661
|
+
onCapture={(r) => {
|
|
1662
|
+
root = r;
|
|
1663
|
+
}}
|
|
1664
|
+
/>
|
|
1665
|
+
</MonthView>,
|
|
1666
|
+
);
|
|
1667
|
+
|
|
1668
|
+
expect(root!.selected).toBeInstanceOf(Temporal.PlainDate);
|
|
1669
|
+
expect(root!.selected).not.toBeInstanceOf(Date);
|
|
1670
|
+
expect(
|
|
1671
|
+
root!.selectedDates.every((d) => d instanceof Temporal.PlainDate),
|
|
1672
|
+
).toBe(true);
|
|
1673
|
+
expect(root!.hasSelection).toBe(true);
|
|
1674
|
+
|
|
1675
|
+
unmount();
|
|
1676
|
+
});
|
|
1677
|
+
});
|
|
1678
|
+
|
|
1096
1679
|
describe("outsideDays", () => {
|
|
1097
1680
|
const march15 = Temporal.PlainDate.from("2026-03-15");
|
|
1098
1681
|
|
|
@@ -1104,7 +1687,9 @@ describe("outsideDays", () => {
|
|
|
1104
1687
|
</MonthView>,
|
|
1105
1688
|
);
|
|
1106
1689
|
|
|
1107
|
-
const outsideCells = Array.from(
|
|
1690
|
+
const outsideCells = Array.from(
|
|
1691
|
+
container.querySelectorAll("td[data-outside-month]"),
|
|
1692
|
+
);
|
|
1108
1693
|
expect(outsideCells.length).toBeGreaterThan(0);
|
|
1109
1694
|
|
|
1110
1695
|
// None should have data-hidden
|
|
@@ -1130,12 +1715,18 @@ describe("outsideDays", () => {
|
|
|
1130
1715
|
describe('outsideDays="readOnly"', () => {
|
|
1131
1716
|
it("outside-month buttons render but are disabled", () => {
|
|
1132
1717
|
const { container, unmount } = render(
|
|
1133
|
-
<MonthView
|
|
1718
|
+
<MonthView
|
|
1719
|
+
{...defaultProps}
|
|
1720
|
+
defaultValue={march15}
|
|
1721
|
+
outsideDays="readOnly"
|
|
1722
|
+
>
|
|
1134
1723
|
<Grid />
|
|
1135
1724
|
</MonthView>,
|
|
1136
1725
|
);
|
|
1137
1726
|
|
|
1138
|
-
const outsideCells = Array.from(
|
|
1727
|
+
const outsideCells = Array.from(
|
|
1728
|
+
container.querySelectorAll("td[data-outside-month]"),
|
|
1729
|
+
);
|
|
1139
1730
|
expect(outsideCells.length).toBeGreaterThan(0);
|
|
1140
1731
|
|
|
1141
1732
|
for (const cell of outsideCells) {
|
|
@@ -1194,7 +1785,9 @@ describe("outsideDays", () => {
|
|
|
1194
1785
|
</MonthView>,
|
|
1195
1786
|
);
|
|
1196
1787
|
|
|
1197
|
-
const outsideCells = Array.from(
|
|
1788
|
+
const outsideCells = Array.from(
|
|
1789
|
+
container.querySelectorAll("td[data-outside-month]"),
|
|
1790
|
+
);
|
|
1198
1791
|
expect(outsideCells.length).toBeGreaterThan(0);
|
|
1199
1792
|
|
|
1200
1793
|
for (const cell of outsideCells) {
|
|
@@ -1215,12 +1808,18 @@ describe("outsideDays", () => {
|
|
|
1215
1808
|
describe('outsideDays="hidden"', () => {
|
|
1216
1809
|
it("outside-month cells are empty with data-hidden and aria-hidden", () => {
|
|
1217
1810
|
const { container, unmount } = render(
|
|
1218
|
-
<MonthView
|
|
1811
|
+
<MonthView
|
|
1812
|
+
{...defaultProps}
|
|
1813
|
+
defaultValue={march15}
|
|
1814
|
+
outsideDays="hidden"
|
|
1815
|
+
>
|
|
1219
1816
|
<Grid />
|
|
1220
1817
|
</MonthView>,
|
|
1221
1818
|
);
|
|
1222
1819
|
|
|
1223
|
-
const hiddenCells = Array.from(
|
|
1820
|
+
const hiddenCells = Array.from(
|
|
1821
|
+
container.querySelectorAll("[data-hidden]"),
|
|
1822
|
+
);
|
|
1224
1823
|
expect(hiddenCells.length).toBeGreaterThan(0);
|
|
1225
1824
|
|
|
1226
1825
|
for (const cell of hiddenCells) {
|
|
@@ -1247,7 +1846,9 @@ describe("outsideDays", () => {
|
|
|
1247
1846
|
</MonthView>,
|
|
1248
1847
|
);
|
|
1249
1848
|
|
|
1250
|
-
const hiddenCells = Array.from(
|
|
1849
|
+
const hiddenCells = Array.from(
|
|
1850
|
+
container.querySelectorAll("[data-hidden]"),
|
|
1851
|
+
);
|
|
1251
1852
|
expect(hiddenCells.length).toBeGreaterThan(0);
|
|
1252
1853
|
|
|
1253
1854
|
for (const cell of hiddenCells) {
|
|
@@ -1284,7 +1885,9 @@ describe("outsideDays", () => {
|
|
|
1284
1885
|
expect(rangeEnd).not.toBeNull();
|
|
1285
1886
|
expect(rangeEnd!.getAttribute("data-date")).toBe("2026-03-25");
|
|
1286
1887
|
|
|
1287
|
-
const inRangeCells = Array.from(
|
|
1888
|
+
const inRangeCells = Array.from(
|
|
1889
|
+
container.querySelectorAll("[data-in-range]"),
|
|
1890
|
+
);
|
|
1288
1891
|
expect(inRangeCells.length).toBeGreaterThan(0);
|
|
1289
1892
|
|
|
1290
1893
|
for (const cell of inRangeCells) {
|
|
@@ -1296,7 +1899,12 @@ describe("outsideDays", () => {
|
|
|
1296
1899
|
|
|
1297
1900
|
it("works with multi-month: each grid hides its own outside-month cells", () => {
|
|
1298
1901
|
const { container, unmount } = render(
|
|
1299
|
-
<MonthView
|
|
1902
|
+
<MonthView
|
|
1903
|
+
{...defaultProps}
|
|
1904
|
+
defaultValue={march15}
|
|
1905
|
+
numberOfMonths={2}
|
|
1906
|
+
outsideDays="hidden"
|
|
1907
|
+
>
|
|
1300
1908
|
<Grid monthIndex={0} />
|
|
1301
1909
|
<Grid monthIndex={1} />
|
|
1302
1910
|
</MonthView>,
|
|
@@ -1334,21 +1942,25 @@ describe("outsideDays", () => {
|
|
|
1334
1942
|
|
|
1335
1943
|
const grids = Array.from(container.querySelectorAll("[role='grid']"));
|
|
1336
1944
|
|
|
1337
|
-
const grid0Hidden = Array.from(
|
|
1945
|
+
const grid0Hidden = Array.from(
|
|
1946
|
+
grids[0]!.querySelectorAll("[data-hidden]"),
|
|
1947
|
+
);
|
|
1338
1948
|
for (const cell of grid0Hidden) {
|
|
1339
1949
|
expect(cell.getAttribute("data-in-range")).toBeNull();
|
|
1340
1950
|
}
|
|
1341
1951
|
|
|
1342
|
-
const grid1Hidden = Array.from(
|
|
1952
|
+
const grid1Hidden = Array.from(
|
|
1953
|
+
grids[1]!.querySelectorAll("[data-hidden]"),
|
|
1954
|
+
);
|
|
1343
1955
|
for (const cell of grid1Hidden) {
|
|
1344
1956
|
expect(cell.getAttribute("data-in-range")).toBeNull();
|
|
1345
1957
|
}
|
|
1346
1958
|
|
|
1347
|
-
const rangeStartInGrid0 = grids[0]
|
|
1959
|
+
const rangeStartInGrid0 = grids[0]!.querySelector("[data-range-start]");
|
|
1348
1960
|
expect(rangeStartInGrid0).not.toBeNull();
|
|
1349
1961
|
expect(rangeStartInGrid0!.getAttribute("data-date")).toBe("2026-03-25");
|
|
1350
1962
|
|
|
1351
|
-
const rangeEndInGrid1 = grids[1]
|
|
1963
|
+
const rangeEndInGrid1 = grids[1]!.querySelector("[data-range-end]");
|
|
1352
1964
|
expect(rangeEndInGrid1).not.toBeNull();
|
|
1353
1965
|
expect(rangeEndInGrid1!.getAttribute("data-date")).toBe("2026-04-05");
|
|
1354
1966
|
|
|
@@ -1359,7 +1971,12 @@ describe("outsideDays", () => {
|
|
|
1359
1971
|
const feb15 = Temporal.PlainDate.from("2026-02-15");
|
|
1360
1972
|
|
|
1361
1973
|
const { container, unmount } = render(
|
|
1362
|
-
<MonthView
|
|
1974
|
+
<MonthView
|
|
1975
|
+
{...defaultProps}
|
|
1976
|
+
defaultValue={feb15}
|
|
1977
|
+
fixedWeeks
|
|
1978
|
+
outsideDays="hidden"
|
|
1979
|
+
>
|
|
1363
1980
|
<Grid />
|
|
1364
1981
|
</MonthView>,
|
|
1365
1982
|
);
|
|
@@ -1367,7 +1984,7 @@ describe("outsideDays", () => {
|
|
|
1367
1984
|
const rows = container.querySelectorAll("tbody tr");
|
|
1368
1985
|
expect(rows.length).toBe(6);
|
|
1369
1986
|
|
|
1370
|
-
const lastRow = rows[rows.length - 1]
|
|
1987
|
+
const lastRow = rows[rows.length - 1]!;
|
|
1371
1988
|
const cells = lastRow.querySelectorAll("td");
|
|
1372
1989
|
const allHidden = Array.from(cells).every(
|
|
1373
1990
|
(cell) => cell.getAttribute("data-hidden") !== null,
|
|
@@ -1399,7 +2016,9 @@ describe("outsideDays", () => {
|
|
|
1399
2016
|
|
|
1400
2017
|
const grids1 = Array.from(c1.querySelectorAll("[role='grid']"));
|
|
1401
2018
|
// Grid 0 (March): April dates should have no range attrs
|
|
1402
|
-
const outsideInGrid0 = Array.from(
|
|
2019
|
+
const outsideInGrid0 = Array.from(
|
|
2020
|
+
grids1[0]!.querySelectorAll("[data-outside-month]"),
|
|
2021
|
+
);
|
|
1403
2022
|
for (const cell of outsideInGrid0) {
|
|
1404
2023
|
expect(cell.getAttribute("data-in-range")).toBeNull();
|
|
1405
2024
|
}
|
|
@@ -1423,7 +2042,7 @@ describe("outsideDays", () => {
|
|
|
1423
2042
|
const grids2 = Array.from(c2.querySelectorAll("[role='grid']"));
|
|
1424
2043
|
// Grid 0 (March): April dates should still have range attrs with readonly
|
|
1425
2044
|
const outsideInGrid0Readonly = Array.from(
|
|
1426
|
-
grids2[0]
|
|
2045
|
+
grids2[0]!.querySelectorAll("[data-outside-month][data-in-range]"),
|
|
1427
2046
|
);
|
|
1428
2047
|
expect(outsideInGrid0Readonly.length).toBeGreaterThan(0);
|
|
1429
2048
|
|