Fragiola

API: components

Calendar

A month grid for choosing one date, with the APG date grid's keyboard, plain dates with no time zone and the locale's names from Intl, in each framework.

A month grid for choosing one date. It is an ARIA grid with one tab stop, the keyboard of the WAI-ARIA APG date picker dialog example (the grid pattern). A start and an end date is a RangeCalendar; a calendar in a popup is a DatePicker. Several dates are a MultipleCalendar; presets and day, month and year views are opt-in parts of any calendar.

A date is a plain { year, month, day } (PlainDate, month 1–12) with no time and no time zone, and no date library: the math is the toolkit's @fragiola/primitives/date, which only the calendar and picker entries import. The month heading, the weekday names, the day numbers and each cell's full date name come from Intl for the locale: the one exception to "no text", and the consumer can replace each one.

Trip dates
Gallery

Behaviour

  • Focus: the grid is one tab stop, the focused date's cell. It starts at the value, else today, kept inside min and max.
  • Keyboard: the arrows move a day and a week (left and right swap in right-to-left), Home and End go to the start and end of the week, Page Up and Page Down a month, with Shift a year; Enter and Space choose. Moving past the visible months shows the next ones, and the cell of the new month takes the focus within the same key, so a quick second key reaches it.
  • Bounds: dates before min or after max are disabled (the keyboard never goes there); unavailable dates (isDateUnavailable) can be focused but not chosen; the leading and trailing days of other months can neither be focused nor chosen.
  • Pages: PrevButton and NextButton move by visibleMonths and keep the focus; the focused date follows. They are disabled when the next page would only hold disabled dates.
  • Locale: locale (default: the document's lang, followed when it changes, then the browser's) gives the names and the first day of the week (firstDayOfWeek overrides it).
  • Grid: six weeks always, so it never changes height. The month Heading of offset 0 is announced (aria-live).
  • Calendar systems: calendar={persian} (one export per system from @fragiola/primitives/calendar-systems) shows the system's months: a month starts on its day 1, the heading and cells are its names, Page Up and Page Down move by its months and years. The value stays an ISO PlainDate, so a DateField with the same system, or none, reads it as it is. Without calendar, a locale whose calendar is not Gregorian (fa-IR) keeps the ISO grid with Intl's names.
Persian calendar
Gallery

Anatomy

partelementdata-primitives-partrole
Rootdivcalendar-rootholds the state
Headingh2calendar-headingthe month a grid shows (it names the grid)
PrevButtonbuttoncalendar-prev-buttonshows the previous page of months
NextButtonbuttoncalendar-next-buttonshows the next page of months
Gridtablecalendar-gridone month
GridHeadertheadcalendar-grid-headerthe weekday row (with its tr)
HeaderCellthcalendar-header-cellone weekday
GridBodytbodycalendar-grid-bodythe six weeks
Rowtrcalendar-rowone week
Celltdcalendar-cellone date

Usage

import { Calendar, type PlainDate } from "@fragiola/primitives-react/calendar";

const [date, setDate] = useState<PlainDate | null>(null);

<Calendar.Root value={date} onValueChange={setDate} locale="en-US">
    <Calendar.PrevButton aria-label="Previous month">‹</Calendar.PrevButton>
    <Calendar.Heading />
    <Calendar.NextButton aria-label="Next month">›</Calendar.NextButton>
    <Calendar.Grid>
        <Calendar.GridHeader>
            {(weekday) => <Calendar.HeaderCell key={weekday.index} weekday={weekday} />}
        </Calendar.GridHeader>
        <Calendar.GridBody>
            {(week) => (
                <Calendar.Row key={week[0]?.day} week={week}>
                    {(date) => <Calendar.Cell key={date.day} date={date} />}
                </Calendar.Row>
            )}
        </Calendar.GridBody>
    </Calendar.Grid>
</Calendar.Root>;

GridHeader, GridBody and Row render their default parts when given no children.

Props

Every part also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards. The names below are React's; Vue binds them the same way (v-model:value, @value-change, :visible-months), and Angular as inputs and outputs ([(value)], (valueChangeDetails), [visibleMonths]).

Root

proptypedefaultdescription
valuePlainDate | nullthe chosen date, controlled
defaultValuePlainDate | nullnullthe initial date, uncontrolled
onValueChange(value: PlainDate | null, details: { reason }) => voidevery choice (reason item-press)
minPlainDate | nulldates before it are disabled
maxPlainDate | nulldates after it are disabled
isDateUnavailable(date: PlainDate) => booleanunavailable dates can be focused, not chosen
localestringthe document's langa BCP 47 tag: the names and the first day of the week
calendarCalendarSystemthe ISO calendara calendar system (persian from @fragiola/primitives/calendar-systems): the grid's months, names and Page Up / Down are its own; values stay ISO
firstDayOfWeeknumberthe locale's0–6, Sunday is 0
visibleMonthsnumber1how many months are shown, each a Grid with its offset
disabledbooleanfalsenothing can be focused or chosen
readOnlybooleanfalsedates can be focused, not chosen

Heading

proptypedefaultdescription
offsetnumber0which visible month it names

PrevButton

No props of its own.

NextButton

No props of its own.

Grid

proptypedefaultdescription
offsetnumber0which visible month it shows

GridHeader

No props of its own: React's children are a function of each weekday, Vue's default slot gets { weekday }, Angular's weekdays() lists them.

HeaderCell

proptypedefaultdescription
weekdayWeekday{ index, short, long }: its text is short, its abbr is long

GridBody

No props of its own: React's children are a function of each week, Vue's default slot gets { week }, Angular's weeks() lists them.

Row

proptypedefaultdescription
week (react, vue)PlainDate[]its seven dates; Angular loops over the week itself

Cell

proptypedefaultdescription
datePlainDateits date; its name is the full date from Intl unless it has an aria-label

State and part attributes

partattributes
Rootdata-disabled, data-readonly
Headingan id, aria-live="polite" (offset 0)
PrevButton, NextButtontype="button", aria-controls (the grids), disabled and data-disabled when they cannot move
Gridrole="grid", aria-labelledby (its Heading), aria-readonly, aria-disabled
HeaderCellscope="col", abbr
Cellrole="gridcell", aria-label, tabindex (0 on the focused date, -1 on the month's other dates, none on other months' days), aria-selected, aria-disabled, aria-current="date" (today); data-today, data-selected, data-disabled, data-unavailable, data-outside-month

Keyboard

keymoves the focused date to
ArrowRight / ArrowLeftthe next / previous day (swapped in right-to-left)
ArrowDown / ArrowUpthe same day of the next / previous week
Home / Endthe first / last day of its week
PageDown / PageUpthe same day of the next / previous month
Shift+PageDown / Shift+PageUpthe same day of the next / previous year
Enter, Spacechooses it

Exports

entryexports
@fragiola/primitives-react/calendarCalendar, CalendarCellProps, CalendarCellState, CalendarGridBodyProps, CalendarGridHeaderProps, CalendarGridProps, CalendarHeaderCellProps, CalendarHeaderCellState, CalendarHeadingProps, CalendarHeadingState, CalendarNextButtonProps, CalendarOptions, CalendarPageButtonState, CalendarPrevButtonProps, CalendarRootProps, CalendarRootSharedProps, CalendarRootState, CalendarRowProps, ChangeDetails, ChangeReason, DateRange, PlainDate, RenderProp, Weekday
@fragiola/primitives-vue/calendarCalendar, CalendarCellProps, CalendarCellState, CalendarGridBodySlots, CalendarGridHeaderSlots, CalendarGridProps, CalendarHeaderCellProps, CalendarHeaderCellState, CalendarHeadingProps, CalendarHeadingState, CalendarNextButtonProps, CalendarOptions, CalendarPageButtonState, CalendarPrevButtonProps, CalendarRootEmits, CalendarRootProps, CalendarRootSharedProps, CalendarRootState, CalendarRowProps, CalendarRowSlots, ChangeDetails, ChangeReason, DateRange, PlainDate, RenderSlotProps, Weekday
@fragiola/primitives-angular/calendarCalendarRoot, CALENDAR, CalendarCell, CalendarCellState, CalendarComponent, CalendarGrid, CalendarGridBody, CalendarGridHeader, CalendarHeaderCell, CalendarHeading, CalendarInputs, CalendarMode, CalendarNextButton, CalendarNextButtonState, CalendarOptions, CalendarPrevButton, CalendarPrevButtonState, CalendarRootBase, CalendarRow, CalendarState, CalendarValue, ChangeDetails, ChangeReason, DateRange, injectCalendar, PICKER_BINDING, PickerBinding, PlainDate, ValueChangeEvent, Weekday