Fragiola

API: components

YearRangeCalendar

The year grid for choosing a start and an end year, with a preview while the range is being chosen.

The YearCalendar's grid for choosing a range of years: a year filter. Its parts are the MonthCalendar's, named year-range-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 (its start), else the year holding today, kept inside min and max.
  • 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 / max are 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.
  • Range: the first choice starts the range (hovering or focusing an item previews it, data-range-preview), the second ends it, swapped when it comes first; onValueChange fires once, with the whole range. Escape cancels a started range, before an enclosing picker closes.
  • 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 YearRangePicker.

Anatomy

partelementdata-primitives-partrole
Rootdivyear-range-calendar-rootholds the state
Headingh2year-range-calendar-headingthe page's span of years shown (it names the grid)
PrevButtonbuttonyear-range-calendar-prev-buttonshows the previous page
NextButtonbuttonyear-range-calendar-next-buttonshows the next page
Gridtableyear-range-calendar-gridthe page
GridBodytbodyyear-range-calendar-grid-bodyits rows
Rowtryear-range-calendar-rowone row
Celltdyear-range-calendar-cellone year

Usage

import { YearRangeCalendar, type YearRange } from "@fragiola/primitives-react/year-range-calendar";

const [value, setValue] = useState<YearRange | null>(null);

<YearRangeCalendar.Root value={value} onValueChange={setValue} locale="en-US">
    <YearRangeCalendar.PrevButton aria-label="Previous years">‹</YearRangeCalendar.PrevButton>
    <YearRangeCalendar.Heading />
    <YearRangeCalendar.NextButton aria-label="Next years">›</YearRangeCalendar.NextButton>
    <YearRangeCalendar.Grid>
        <YearRangeCalendar.GridBody>
            {(row) => (
                <YearRangeCalendar.Row key={row[0]?.year} row={row}>
                    {(item) => <YearRangeCalendar.Cell key={JSON.stringify(item)} value={item} />}
                </YearRangeCalendar.Row>
            )}
        </YearRangeCalendar.GridBody>
    </YearRangeCalendar.Grid>
</YearRangeCalendar.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

proptypedefaultdescription
valueYearRange | nullthe chosen range, controlled
defaultValueYearRange | nullnullthe initial range, uncontrolled
onValueChange(value: YearRange | null, details: { reason }) => voidevery choice (reason item-press)
minPlainYear | nullyears before it are disabled
maxPlainYear | nullyears after it are disabled
isUnavailable(year: PlainYear) => booleanunavailable years can be focused, not chosen
localestringthe document's langa BCP 47 tag: the names
calendarCalendarSystemthe ISO calendara 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])
columnsnumber3items per row
disabledbooleanfalsenothing can be focused or chosen
readOnlybooleanfalseyears 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

proptypedefaultdescription
row (react, vue)PlainYearMonth[] | PlainYear[]its items; Angular loops over the row itself

Cell

proptypedefaultdescription
valuePlainYearMonth | PlainYearits month or year; its name is the full name from Intl unless it has an aria-label

State and part attributes

partattributes
Rootdata-disabled, data-readonly
Headingan id, aria-live="polite"
PrevButton, NextButtontype="button", aria-controls (the grid), disabled and data-disabled when they cannot move
Gridrole="grid", aria-labelledby (the Heading), aria-readonly, aria-disabled, aria-multiselectable="true"
Cellrole="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, data-range-start, data-range-end, data-in-range, data-range-preview

Keyboard

keymoves the focused item to
ArrowRight / ArrowLeftthe next / previous item (swapped in right-to-left)
ArrowDown / ArrowUpthe item below / above (columns items on)
Home / Endthe first / last item of its row
PageDown / PageUpthe same place on the next / previous page (12 years)
Enter, Spacechooses it
Escapein a range calendar with a started range, cancels it

Exports

entryexports
@fragiola/primitives-react/year-range-calendarChangeDetails, ChangeReason, MonthCalendar, MonthCalendarCellProps, MonthCalendarCellState, MonthCalendarGridBodyProps, MonthCalendarGridProps, MonthCalendarHeadingProps, MonthCalendarHeadingState, MonthCalendarItem, MonthCalendarNextButtonProps, MonthCalendarPageButtonState, MonthCalendarPrevButtonProps, MonthCalendarRootSharedProps, MonthCalendarRootState, MonthCalendarRowProps, PlainYear, PlainYearMonth, RenderProp, YearMonthRange, YearRange, YearRangeCalendar, YearRangeCalendarRootProps
@fragiola/primitives-vue/year-range-calendarChangeDetails, ChangeReason, MonthCalendar, MonthCalendarCellProps, MonthCalendarCellState, MonthCalendarGridBodySlots, MonthCalendarGridProps, MonthCalendarHeadingProps, MonthCalendarHeadingState, MonthCalendarItem, MonthCalendarNextButtonProps, MonthCalendarPageButtonState, MonthCalendarPrevButtonProps, MonthCalendarRootSharedProps, MonthCalendarRootState, MonthCalendarRowProps, MonthCalendarRowSlots, PlainYear, PlainYearMonth, RenderSlotProps, YearMonthRange, YearRange, YearRangeCalendar, YearRangeCalendarRootEmits, YearRangeCalendarRootProps
@fragiola/primitives-angular/year-range-calendarChangeDetails, ChangeReason, MonthCalendarCell, MonthCalendarCellState, MonthCalendarGrid, MonthCalendarGridBody, MonthCalendarHeading, MonthCalendarItem, MonthCalendarNextButton, MonthCalendarNextButtonState, MonthCalendarPrevButton, MonthCalendarPrevButtonState, MonthCalendarRow, PlainYear, PlainYearMonth, ValueChangeEvent, YearMonthRange, YearRange, YearRangeCalendarRoot