Month/year dropdown lands on 1976 instead of the current year (WEB-1295)
Version: 0.9.0 ยท Type: ๐ Bug Fix
Problemโ
Opening the month / year dropdown in the Calendar (DatePicker) always scrolled to the top of the list. For the year dropdown this meant the panel showed 1976 (the earliest year) every time, even though the currently selected year was e.g. 2026 โ users had to scroll all the way down to reach the current year. The month dropdown had the same latent issue.
Root Causeโ
CalendarMonthCaption renders the month/year dropdowns with Radix DropdownMenu. The year list spans the current year ยฑ50 (START_YEAR = CURRENT_YEAR - 50 โฆ END_YEAR = CURRENT_YEAR + 50), i.e. 101 items in a max-h-[280px] scroll container. On open, Radix focuses the first list item and scrolls it into view, so the container stayed pinned to the top (1976) and the selected year was scrolled out of sight. The component had no "scroll the selected item into view on open" logic.
Changed Filesโ
packages/design/src/components/Calendar/CalendarMonthCaption.tsxpackages/design/src/components/Calendar/__tests__/Calendar.test.tsx
Changesโ
- Tag the current month / current year
DropdownMenuItemEntrywithitemProps: { 'data-current': 'true' }(month byi === currentMonth, year byyear === currentYear); addcurrentMonthto themonthItemsuseMemodeps. - Prefix both dropdowns'
contentClassNamewith apd-calendar__scroll-menumarker class (the scroll container is the content wrapper carryingmax-h-[280px] overflow-y-auto). - Add a
useEffect(deps[monthOpen, yearOpen]): when either dropdown opens, after onerequestAnimationFrame(waiting for Radix's first-item autofocus + layout) it iterates.pd-calendar__scroll-menu, focuses the[data-current]item withfocus({ preventScroll: true })(moving keyboard focus off the first item), then centers it within the scroll container via agetBoundingClientRectdelta applied toscrollToponly (no page scroll). The cleanup cancels the frame. - Add 2 regression tests: opening the year dropdown asserts a
[role="menuitem"][data-current="true"]containing2026; opening the month dropdown asserts the current item containsJunโ locking the marker contract (happy-dom cannot verify real scrolling sincegetBoundingClientRectreturns 0).
Impactโ
Every consumer of Calendar / DatePicker (via CalendarMonthCaption). Closed-dropdown visuals and behavior are unchanged; only the open month/year dropdown now centers the currently selected item. web4 consumes @plaud/design via workspace:* (source), so the fix takes effect without a release.