API: components
YearCalendar
A grid of a page of 12 years for choosing one year, with the calendar's keys mapped to years.
A grid of a page of 12 years (starting at a multiple of 12: 2016 – 2027 holds 2026) for choosing one year. A range of years is a YearRangeCalendar, a year in a popup a YearPicker. Its parts are the MonthCalendar's, named year-calendar-*.
A year is a plain { year } (PlainYear), with no day and no time zone, from the toolkit's
@fragiola/primitives/month-year, which only the month and year entries import. The grid is
the WAI-ARIA APG grid pattern with the
Calendar's keys mapped to years; the names come from Intl for the locale.
Behaviour
- Page: 12 years in rows of
columns(default 3, so 4 rows); paging never shifts the rows. - Focus: the grid is one tab stop, the focused year's cell. It starts at the value, else the year holding today, kept inside
minandmax. - Keyboard: the arrows move one year and one row (left and right swap in right-to-left), Home and End go to the row's ends, Page Up and Page Down one page (12 years); Enter and Space choose. Moving off the page shows the next one, its cell taking the focus within the same key.
- Bounds: years outside
min/maxare disabled (never focused); unavailable ones (isUnavailable) can be focused, not chosen. PrevButton and NextButton keep the focus and are disabled when the next page holds only disabled years. - Names: a year cell reads and is named the year ("2026"); the Heading is the page's span ("2016 – 2027",
formatRange, its spaces written as plain spaces so a server's text is the browser's); the consumer can replace each one. - In a picker or a view: with no value of its own it binds to a YearPicker or to a CalendarView.
Anatomy
| part | element | data-primitives-part | role |
|---|---|---|---|
| Root | div | year-calendar-root | holds the state |
| Heading | h2 | year-calendar-heading | the page's span of years shown (it names the grid) |
| PrevButton | button | year-calendar-prev-button | shows the previous page |
| NextButton | button | year-calendar-next-button | shows the next page |
| Grid | table | year-calendar-grid | the page |
| GridBody | tbody | year-calendar-grid-body | its rows |
| Row | tr | year-calendar-row | one row |
| Cell | td | year-calendar-cell | one year |
Usage
import { YearCalendar, type PlainYear } from "@fragiola/primitives-react/year-calendar";
const [value, setValue] = useState<PlainYear | null>(null);
<YearCalendar.Root value={value} onValueChange={setValue} locale="en-US">
<YearCalendar.PrevButton aria-label="Previous years">‹</YearCalendar.PrevButton>
<YearCalendar.Heading />
<YearCalendar.NextButton aria-label="Next years">›</YearCalendar.NextButton>
<YearCalendar.Grid>
<YearCalendar.GridBody>
{(row) => (
<YearCalendar.Row key={row[0]?.year} row={row}>
{(item) => <YearCalendar.Cell key={JSON.stringify(item)} value={item} />}
</YearCalendar.Row>
)}
</YearCalendar.GridBody>
</YearCalendar.Grid>
</YearCalendar.Root>;GridBody and Row render their default parts when given no children.
Props
Every part also takes what the primitive contract gives. The
names below are React's; Vue binds them the same way (v-model:value, @value-change), and
Angular as inputs and outputs ([(value)], (valueChangeDetails)).
Root
| prop | type | default | description |
|---|---|---|---|
value | PlainYear | null | the chosen year, controlled | |
defaultValue | PlainYear | null | null | the initial year, uncontrolled |
onValueChange | (value: PlainYear | null, details: { reason }) => void | every choice (reason item-press) | |
min | PlainYear | null | years before it are disabled | |
max | PlainYear | null | years after it are disabled | |
isUnavailable | (year: PlainYear) => boolean | unavailable years can be focused, not chosen | |
locale | string | the document's lang | a BCP 47 tag: the names |
calendar | CalendarSystem | the ISO calendar | a calendar system: the items are its years, and so are the values (a form submits the first day's ISO date, 2026-10-23[u-ca=persian]) |
columns | number | 3 | items per row |
disabled | boolean | false | nothing can be focused or chosen |
readOnly | boolean | false | years can be focused, not chosen |
Heading
No props of its own: its text is the year (a month calendar) or the page's span of years (a year
calendar), from Intl, unless it has children.
PrevButton
No props of its own.
NextButton
No props of its own.
Grid
No props of its own.
GridBody
No props of its own: React's children are a function of each row, Vue's default slot gets
{ row }, Angular's rows() lists them.
Row
| prop | type | default | description |
|---|---|---|---|
row (react, vue) | PlainYearMonth[] | PlainYear[] | its items; Angular loops over the row itself |
Cell
| prop | type | default | description |
|---|---|---|---|
value | PlainYearMonth | PlainYear | its month or year; its name is the full name from Intl unless it has an aria-label |
State and part attributes
| part | attributes |
|---|---|
| Root | data-disabled, data-readonly |
| Heading | an id, aria-live="polite" |
| PrevButton, NextButton | type="button", aria-controls (the grid), disabled and data-disabled when they cannot move |
| Grid | role="grid", aria-labelledby (the Heading), aria-readonly, aria-disabled |
| Cell | role="gridcell", aria-label, tabindex (0 on the focused item, -1 on the others), aria-selected, aria-disabled, aria-current="date" (the item holding today); data-today, data-selected, data-disabled, data-unavailable |
Keyboard
| key | moves the focused item to |
|---|---|
| ArrowRight / ArrowLeft | the next / previous item (swapped in right-to-left) |
| ArrowDown / ArrowUp | the item below / above (columns items on) |
| Home / End | the first / last item of its row |
| PageDown / PageUp | the same place on the next / previous page (12 years) |
| Enter, Space | chooses it |
| Escape | in a range calendar with a started range, cancels it |
Exports
| entry | exports |
|---|---|
@fragiola/primitives-react/year-calendar | ChangeDetails, ChangeReason, MonthCalendar, MonthCalendarCellProps, MonthCalendarCellState, MonthCalendarGridBodyProps, MonthCalendarGridProps, MonthCalendarHeadingProps, MonthCalendarHeadingState, MonthCalendarItem, MonthCalendarNextButtonProps, MonthCalendarPageButtonState, MonthCalendarPrevButtonProps, MonthCalendarRootSharedProps, MonthCalendarRootState, MonthCalendarRowProps, PlainYear, PlainYearMonth, RenderProp, YearCalendar, YearCalendarRootProps, YearMonthRange, YearRange |
@fragiola/primitives-vue/year-calendar | ChangeDetails, ChangeReason, MonthCalendar, MonthCalendarCellProps, MonthCalendarCellState, MonthCalendarGridBodySlots, MonthCalendarGridProps, MonthCalendarHeadingProps, MonthCalendarHeadingState, MonthCalendarItem, MonthCalendarNextButtonProps, MonthCalendarPageButtonState, MonthCalendarPrevButtonProps, MonthCalendarRootSharedProps, MonthCalendarRootState, MonthCalendarRowProps, MonthCalendarRowSlots, PlainYear, PlainYearMonth, RenderSlotProps, YearCalendar, YearCalendarRootEmits, YearCalendarRootProps, YearMonthRange, YearRange |
@fragiola/primitives-angular/year-calendar | ChangeDetails, ChangeReason, MonthCalendarCell, MonthCalendarCellState, MonthCalendarGrid, MonthCalendarGridBody, MonthCalendarHeading, MonthCalendarItem, MonthCalendarNextButton, MonthCalendarNextButtonState, MonthCalendarPrevButton, MonthCalendarPrevButtonState, MonthCalendarRow, PlainYear, PlainYearMonth, ValueChangeEvent, YearCalendarRoot, YearMonthRange, YearRange |