fix: default birth picker to 1997

This commit is contained in:
Jesse_Chen
2026-07-19 17:11:12 +08:00
parent 1935b9f0a6
commit 02eccede4a
2 changed files with 13 additions and 1 deletions
@@ -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}
@@ -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\}/)
})