API: components
DateRangePicker
A trigger and a non-modal popup holding a bound RangeCalendar, which closes on the range's end and returns focus to the trigger, in each framework.
A RangeCalendar in a popup: the DatePicker's trigger, positioner and popup for a range. The popup stays open after the first date and closes on the second. Its RangeCalendar can take presets and views; a range of months or years is a MonthRangePicker or a YearRangePicker.
Its parts are the DatePicker's (WAI-ARIA APG dialog pattern,
non-modal): /date-range-picker exports its own Root with them, named date-range-picker-*.
The RangeCalendar inside the Popup has no value of its own: it binds to the picker, showing its
value and setting it, and takes the picker's calendar options (min, max, locale, ...).
The picker renders no text: the trigger's content is the consumer's (the formatted value, for
example), and so is the popup's name (aria-label).
Behaviour
- Open: a press on the Trigger toggles it. The calendar focuses its focused date: the value
(the range's start), else today, kept inside
minandmax. - Choose: choosing the range's end sets the value, closes the popup (reason
item-press) and focuses the Trigger. - Close: Escape (
escape-key) and the Trigger (trigger-press) return focus to the trigger; a press outside (outside-press) returns it unless the press landed on a focusable element. - Tab order: focus is not trapped. The popup's content comes right after the trigger: Tab from
its last element moves on and closes it, Shift+Tab from its first goes back to the trigger and
closes it (
focus-out). - Positioning: as a Popover's, below the trigger and aligned to its start by default.
- Forms: with a
name, the Root renders a hidden input after its children, which the form submits as one entry, the ISO 8601 intervalname=<start>/<end>(stay=2026-11-25/2026-11-27), or an empty value until both ends are chosen.requiredblocks a native submission with no range and focuses the Trigger;disableddisables the Trigger and submits nothing;readOnlystill opens the popup, whose calendar can be browsed but chooses nothing. A form reset returns an uncontrolled picker to itsdefaultValue. - Field: inside a Field, the field's
nameanddisabledwin, the Trigger is the labelled element and the focus target,validatereceives the range{ start, end }(ornull), and the hidden input is the validated element. The Trigger is named by the Field's Label, then its own content ("Stay 2026-11-25 – 2026-11-27"); a click on the Label only focuses it. A Fieldset'sdisableddisables it too. - Lifecycle:
onOpenChangeis called before the change (details.cancel()keeps it as it is, change details),onOpenChangeComplete(open)reports the end of each transition, the actionsclose()andunmount()act from code, and the Portal'skeepMountedkeeps the Positioner in the page while closed (hidden,data-closed).
Anatomy
| part | element | data-primitives-part | role |
|---|---|---|---|
| Root | none | holds the value and the open state | |
| Trigger | button | date-range-picker-trigger | toggles the popup, and anchors it |
| Portal | none | moves the Positioner to the end of body | |
| Positioner | div | date-range-picker-positioner | places the popup next to the trigger |
| Popup | div | date-range-picker-popup | the non-modal dialog, holding a RangeCalendar.Root |
| (hidden input) | input | date-range-picker-input | rendered after the Root's children while it has a name (or a Field's): what the form submits |
Usage
import { RangeCalendar } from "@fragiola/primitives-react/range-calendar";
import { DateRangePicker, type DateRange } from "@fragiola/primitives-react/date-range-picker";
const [value, setValue] = useState<DateRange | null>(null);
<DateRangePicker.Root value={value} onValueChange={setValue} locale="en-US">
<DateRangePicker.Trigger>{value ? format(value) : "Choose dates"}</DateRangePicker.Trigger>
<DateRangePicker.Portal>
<DateRangePicker.Positioner sideOffset={4}>
<DateRangePicker.Popup aria-label="Choose dates">
<RangeCalendar.Root>
{/* its Heading, page buttons and Grid, as on the RangeCalendar page */}
</RangeCalendar.Root>
</DateRangePicker.Popup>
</DateRangePicker.Positioner>
</DateRangePicker.Portal>
</DateRangePicker.Root>;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, v-model:open,
:side-offset), and Angular as inputs and outputs ([(value)], [(open)],
(valueChangeDetails), (openChangeDetails)).
Root
| prop | type | default | description |
|---|---|---|---|
value | DateRange | null | the chosen range, controlled | |
defaultValue | DateRange | null | null | the initial range, uncontrolled |
onValueChange | (value: DateRange | null, details: { reason }) => void | every choice (reason item-press) | |
open | boolean | the open state, controlled | |
defaultOpen | boolean | false | the initial open state, uncontrolled |
onOpenChange | (open: boolean, details: OpenChangeDetails) => void | every change, with its reason (trigger-press, item-press, escape-key, outside-press, focus-out); called before the change, details.cancel() stops it | |
onOpenChangeComplete | (open: boolean) => void | once an opening or a closing has finished its transitions (not on the first render, nor for an exit a reopening interrupted) | |
actionsRef (react) | { current: OverlayActions | null } | receives close() (reason imperative-action) and unmount() (ends an exit now); Vue exposes them on the Root's template ref, Angular as the root directive's methods | |
min | PlainDate | null | passed to the bound calendar | |
max | PlainDate | null | passed to the bound calendar | |
isDateUnavailable | (date: PlainDate) => boolean | passed to the bound calendar | |
locale | string | the document's lang | passed to the bound calendar |
calendar | CalendarSystem | the ISO calendar | a calendar system, passed to the bound calendar; the range stays ISO |
firstDayOfWeek | number | the locale's | passed to the bound calendar |
visibleMonths | number | 1 | passed to the bound calendar |
name | string | the hidden input's form name (a Field's wins); without one, no input is rendered | |
required | boolean | false | a native form's validation blocks a submission with no range |
disabled | boolean | false | the Trigger cannot open the popup; the hidden input submits nothing |
readOnly | boolean | false | the popup still opens; its calendar can be browsed, no date chosen |
Trigger
No props of its own.
Portal
| prop | type | default | description |
|---|---|---|---|
container (react, vue) | Element | document.body | where the Positioner goes |
keepMounted (react, vue) | boolean | false | keep the content rendered while closed (before the first opening and after an exit), hidden and data-closed; reopening shows the same elements |
options (angular) | Element | { container?, keepMounted? } | {} | the same two options: *datePickerPortal="{ keepMounted: true }", or *datePickerPortal="element" for a container alone |
Positioner
| prop | type | default | description |
|---|---|---|---|
side | "top" | "bottom" | "inline-start" | "inline-end" | "left" | "right" | "bottom" | the side of the trigger |
align | "start" | "center" | "end" | "start" | the alignment along that side |
sideOffset | number | 0 | the distance from the trigger, in px |
alignOffset | number | 0 | the shift along its edge, in px |
collisionPadding | number | 8 | the space kept from the viewport's edges, in px |
anchor | Element | the trigger | the element to place the popup next to |
Popup
No props of its own.
State and part attributes
| part | attributes |
|---|---|
| Trigger | type="button", aria-haspopup="dialog", aria-expanded, aria-controls (the popup while open), data-popup-open; disabled and data-disabled while disabled, data-readonly while read-only, data-required while required; in a Field, its ids, aria-labelledby (the Label, then itself), aria-describedby, aria-invalid and the field's states |
| Positioner | role="presentation", data-side, data-align, data-open / data-closed; the CSS variables --anchor-width, --anchor-height, --available-width, --available-height, --transform-origin; hidden while kept mounted and closed |
| Popup | role="dialog" (no aria-modal), an id, data-side, data-align, data-open / data-closed, data-starting-style, data-ending-style |
| hidden input | name, value (ISO), required, disabled, aria-hidden="true", tabindex="-1"; visually hidden (a text input, which the browser validates, not type="hidden") |
Keyboard
| key | action |
|---|---|
| Enter, Space on the Trigger | toggles |
| the calendar's keys | as on the RangeCalendar page; choosing the range's end closes |
| Tab | through the popup; from its last element, to the element after the trigger, closing it |
| Shift+Tab | from the popup's first element, back to the trigger, closing it |
| Escape | closes, focus on the trigger |
Exports
| entry | exports |
|---|---|
@fragiola/primitives-react/date-range-picker | DateRangePicker, Align, CalendarOptions, ChangeDetails, ChangeReason, DatePickerPopupProps, DatePickerPopupState, DatePickerPortalProps, DatePickerPositionerProps, DatePickerPositionerState, DatePickerRootSharedProps, DatePickerTriggerProps, DatePickerTriggerState, DateRange, DateRangePickerRootProps, PlainDate, PositionerProps, RenderProp, Side, OpenChangeDetails, OverlayActions, OverlayPortalProps, OverlayRootProps |
@fragiola/primitives-vue/date-range-picker | DateRangePicker, Align, CalendarOptions, ChangeDetails, ChangeReason, DatePickerPopupProps, DatePickerPopupState, DatePickerPortalProps, DatePickerFormProps, DatePickerPositionerState, DatePickerRootSharedProps, DatePickerTriggerProps, DatePickerTriggerState, DateRange, DateRangePickerRootEmits, DateRangePickerRootProps, PlainDate, PositionerProps, RenderSlotProps, Side, OpenChangeDetails, OverlayActions, OverlayPortalProps, OverlayRootEmits, OverlayRootProps |
@fragiola/primitives-angular/date-range-picker | DateRangePickerRoot, Align, CalendarOptions, ChangeDetails, ChangeReason, DatePickerPopup, DatePickerPopupState, DatePickerPortal, DatePickerPositioner, DatePickerPositionerState, DatePickerTrigger, DatePickerTriggerState, DateRange, injectDatePicker, OpenChangeEvent, PlainDate, Side, ValueChangeEvent, OpenChangeDetails, OverlayActions, OverlayPortalOptions |