Fragiola

API: components

RangeCalendar

A month grid for choosing a start and an end date, with the Calendar's parts and keyboard and a preview while choosing, in each framework.

The Calendar's grid for a range: the first choice is the start, the second the end, and onValueChange fires once, with { start, end }. It is the same ARIA grid with the keyboard of the WAI-ARIA APG date picker dialog example, marked aria-multiselectable. A range in a popup is a DateRangePicker. Presets ("Last 7 days") set a range in one press; a range of months or years is a MonthRangeCalendar or a YearRangeCalendar.

Its parts are the Calendar's: /range-calendar exports its own Root with them, named range-calendar-* inside it. Dates are plain { year, month, day } values with no time zone; the names come from Intl.

Trip dates
Gallery

Behaviour

  • Choosing: the first choice (a click, Enter or Space) starts the range; while it is pending, hovering or focusing a date previews the range up to it (data-range-preview); the second choice ends it. An end before the start swaps them. Escape cancels a started range.
  • Keyboard, focus, bounds, pages, locale: the Calendar's. Enter that starts a range keeps the focused date where it is.
  • Months: visibleMonths shows several grids side by side; the keyboard crosses them without moving the page, and the page buttons move them all.

Anatomy

partelementdata-primitives-partrole
Rootdivrange-calendar-rootholds the state
Headingh2range-calendar-headingthe month a grid shows
PrevButtonbuttonrange-calendar-prev-buttonshows the previous page of months
NextButtonbuttonrange-calendar-next-buttonshows the next page of months
Gridtablerange-calendar-gridone month
GridHeadertheadrange-calendar-grid-headerthe weekday row
HeaderCellthrange-calendar-header-cellone weekday
GridBodytbodyrange-calendar-grid-bodythe six weeks
Rowtrrange-calendar-rowone week
Celltdrange-calendar-cellone date

Usage

import { type DateRange, RangeCalendar } from "@fragiola/primitives-react/range-calendar";

const [stay, setStay] = useState<DateRange | null>(null);

<RangeCalendar.Root value={stay} onValueChange={setStay} visibleMonths={2} locale="en-US">
    <RangeCalendar.PrevButton aria-label="Previous months">‹</RangeCalendar.PrevButton>
    <RangeCalendar.NextButton aria-label="Next months">›</RangeCalendar.NextButton>
    {[0, 1].map((offset) => (
        <div key={offset}>
            <RangeCalendar.Heading offset={offset} />
            <RangeCalendar.Grid offset={offset}>
                <RangeCalendar.GridHeader />
                <RangeCalendar.GridBody />
            </RangeCalendar.Grid>
        </div>
    ))}
</RangeCalendar.Root>;

Props

Every part also takes what the primitive contract gives. The names below are React's; Vue and Angular bind them as on the Calendar page.

Root

proptypedefaultdescription
valueDateRange | nullthe chosen { start, end }, controlled
defaultValueDateRange | nullnullthe initial range, uncontrolled
onValueChange(value: DateRange | null, details: { reason }) => voidonce per complete range (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
calendarCalendarSystemthe ISO calendara calendar system: the grid's months and names; values stay ISO
firstDayOfWeeknumberthe locale's0–6, Sunday is 0
visibleMonthsnumber1how many months are shown
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

As the Calendar's, and:

partattributes
Gridaria-multiselectable="true"
Cellaria-selected on every date of the range; data-range-start, data-range-end, data-in-range, data-range-preview (between a started range's start and the hovered or focused date)

Keyboard

The Calendar's, and:

keyaction
Enter, Spacestarts the range, then ends it
Escapecancels a started range

Exports

entryexports
@fragiola/primitives-react/range-calendarRangeCalendar, CalendarCellProps, CalendarCellState, CalendarGridBodyProps, CalendarGridHeaderProps, CalendarGridProps, CalendarHeaderCellProps, CalendarHeaderCellState, CalendarHeadingProps, CalendarHeadingState, CalendarNextButtonProps, CalendarOptions, CalendarPageButtonState, CalendarPrevButtonProps, CalendarRootSharedProps, CalendarRootState, CalendarRowProps, ChangeDetails, ChangeReason, DateRange, PlainDate, RangeCalendarRootProps, RenderProp, Weekday
@fragiola/primitives-vue/range-calendarRangeCalendar, CalendarCellProps, CalendarCellState, CalendarGridBodySlots, CalendarGridHeaderSlots, CalendarGridProps, CalendarHeaderCellProps, CalendarHeaderCellState, CalendarHeadingProps, CalendarHeadingState, CalendarNextButtonProps, CalendarOptions, CalendarPageButtonState, CalendarPrevButtonProps, CalendarRootSharedProps, CalendarRootState, CalendarRowProps, CalendarRowSlots, ChangeDetails, ChangeReason, DateRange, PlainDate, RangeCalendarRootEmits, RangeCalendarRootProps, RenderSlotProps, Weekday
@fragiola/primitives-angular/range-calendarRangeCalendarRoot, CalendarCell, CalendarCellState, CalendarGrid, CalendarGridBody, CalendarGridHeader, CalendarHeaderCell, CalendarHeading, CalendarNextButton, CalendarNextButtonState, CalendarOptions, CalendarPrevButton, CalendarPrevButtonState, CalendarRow, ChangeDetails, ChangeReason, DateRange, injectCalendar, PlainDate, ValueChangeEvent, Weekday