Overview
Theapp-year-grid component displays a scrollable grid of years for quick year selection. It’s used internally by app-date-picker but can also be used standalone for custom implementations.
Installation
Import
Usage
This is a low-level component. Most use cases should use app-date-picker instead.
Properties
YearGridData
Year grid data object containing all necessary information to render the grid.
Promise<HTMLButtonElement | null>
Async query for the currently selected year button element.
Promise<HTMLDivElement | null>
Async query for the year grid container element.
Events
year-updated
Fires when a year is selected (clicked or via keyboard).CSS Shadow Parts
Available Parts
year-grid- Main grid containeryear- Individual year buttontoyear- Current year button
Keyboard Navigation
- Arrow Up - Previous row (4 years earlier)
- Arrow Down - Next row (4 years later)
- Arrow Left - Previous year
- Arrow Right - Next year
- Home - First year in range (min)
- End - Last year in range (max)
- Page Up - Previous page (12 years earlier)
- Page Down - Next page (12 years later)
- Enter / Space - Select focused year (native button behavior)
Methods
method
Protected method for rendering individual year buttons. Can be overridden for customization.
Example: Custom Year Range
Example: Styled Year Grid
Example: Integration with Date Picker
TypeScript
Behavior Notes
- The grid displays years in a 4-column layout by default
- Automatically scrolls to show the selected/focused year
- Years are displayed in ascending order (oldest to newest)
- The grid shows all years between
minandmaxdates - Uses semantic
<button>elements for accessibility - Prevents event propagation to work properly within dialogs
- Each button has
tabindex="0"for the focused year,-1for others - The component automatically calculates scroll position based on the selected year