From 02eccede4a19acf7d47b29b202af1a1e87c09c86 Mon Sep 17 00:00:00 2001 From: Jesse_Chen Date: Sun, 19 Jul 2026 17:11:12 +0800 Subject: [PATCH] fix: default birth picker to 1997 --- frontend/src/components/birth-date-picker.tsx | 4 +++- frontend/tests/birth-date-picker-contract.test.ts | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/birth-date-picker.tsx b/frontend/src/components/birth-date-picker.tsx index 8dc3dd01..209f3e7a 100644 --- a/frontend/src/components/birth-date-picker.tsx +++ b/frontend/src/components/birth-date-picker.tsx @@ -17,6 +17,8 @@ type BirthDatePickerProps = { readonly onChange: (value: string) => void; }; +const emptyDefaultMonth = new Date(1997, 0, 1); + export function BirthDatePicker({ value, disabled, onChange }: BirthDatePickerProps) { const labelId = useId(); const valueId = useId(); @@ -53,7 +55,7 @@ export function BirthDatePicker({ value, disabled, onChange }: BirthDatePickerPr className="[--cell-size:2.75rem] [&_button[data-selected-single=true]]:text-primary-foreground!" locale={zhCN} selected={selected} - defaultMonth={selected ?? today} + defaultMonth={selected ?? emptyDefaultMonth} captionLayout="dropdown" startMonth={new Date(1900, 0)} endMonth={today} diff --git a/frontend/tests/birth-date-picker-contract.test.ts b/frontend/tests/birth-date-picker-contract.test.ts index f5310bf1..91d92bd2 100644 --- a/frontend/tests/birth-date-picker-contract.test.ts +++ b/frontend/tests/birth-date-picker-contract.test.ts @@ -33,3 +33,13 @@ test("keeps the shadcn date-of-birth dropdown navigation order", () => { // Then the picker must not move the full-width nav after the caption selects assert.doesNotMatch(picker, /navLayout="after"/) }) + +test("opens an empty birth date picker at 1997 instead of the current year", () => { + // Given: a new user has not selected a birth date yet. + const picker = readFileSync(pickerUrl, "utf8") + + // When: the popover chooses its initial visible month. + // Then: it starts in 1997 so common birth years are nearby. + assert.match(picker, /const emptyDefaultMonth = new Date\(1997, 0, 1\)/) + assert.match(picker, /defaultMonth=\{selected \?\? emptyDefaultMonth\}/) +})