API: components
DatePicker
A trigger and a non-modal popup holding a bound Calendar, which opens on the chosen date, closes on a choice and returns focus to the trigger.
A trigger and a non-modal popup holding a Calendar. The popup is a dialog
disclosed by a button, as a Popover (WAI-ARIA APG
dialog pattern, without the modal
parts), and the calendar inside keeps the keyboard of the APG
date picker dialog example.
A start and an end date is a DateRangePicker. Its calendar can take
presets and day, month and year views; a month or
a year alone is a MonthPicker or a YearPicker.
The Calendar 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 chosen date), else today, kept inside
minandmax. - Choose: choosing a date 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 asname=<ISO date>(arrival=2026-11-24), or an empty value with no date.requiredblocks a native submission with no date and focuses the Trigger;disableddisables the Trigger and submits nothing;readOnlystill opens the popup, whose calendar can be browsed but chooses nothing, and still submits. A form reset returns an uncontrolled picker to itsdefaultValue(a controlled one reports it throughonValueChange, reasonnone). - Field: inside a Field, the field's
nameanddisabledwin, the Trigger is the labelled element and the focus target,validatereceives the date (ornull), and the hidden input is the validated element. The Trigger is named by the Field's Label, then its own content ("Arrival 2026-11-24"), so its visible text stays in its name; a click on the Label only focuses it, and opens nothing. 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-picker-trigger | toggles the popup, and anchors it |
| Portal | none | moves the Positioner to the end of body | |
| Positioner | div | date-picker-positioner | places the popup next to the trigger |
| Popup | div | date-picker-popup | the non-modal dialog, holding a Calendar.Root |
| (hidden input) | input | date-picker-input | rendered after the Root's children while it has a name (or a Field's): what the form submits |
Usage
import { Calendar } from "@fragiola/primitives-react/calendar";
import { DatePicker, type PlainDate } from "@fragiola/primitives-react/date-picker";
const [value, setValue] = useState<PlainDate | null>(null);
<DatePicker.Root value={value} onValueChange={setValue} locale="en-US">
<DatePicker.Trigger>{value ? format(value) : "Choose a date"}</DatePicker.Trigger>
<DatePicker.Portal>
<DatePicker.Positioner sideOffset={4}>
<DatePicker.Popup aria-label="Choose a date">
<Calendar.Root>
{/* its Heading, page buttons and Grid, as on the Calendar page */}
</Calendar.Root>
</DatePicker.Popup>
</DatePicker.Positioner>
</DatePicker.Portal>
</DatePicker.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 | PlainDate | null | the chosen date, controlled | |
defaultValue | PlainDate | null | null | the initial date, uncontrolled |
onValueChange | (value: PlainDate | 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 value 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 date |
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 Calendar page; choosing a date 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-picker | DatePicker, Align, CalendarOptions, ChangeDetails, ChangeReason, DatePickerPopupProps, DatePickerPopupState, DatePickerPortalProps, DatePickerPositionerProps, DatePickerPositionerState, DatePickerRootProps, DatePickerRootSharedProps, DatePickerTriggerProps, DatePickerTriggerState, PlainDate, PositionerProps, RenderProp, Side, OpenChangeDetails, OverlayActions, OverlayPortalProps, OverlayRootProps |
@fragiola/primitives-vue/date-picker | DatePicker, Align, CalendarOptions, ChangeDetails, ChangeReason, DatePickerPopupProps, DatePickerPopupState, DatePickerPortalProps, DatePickerFormProps, DatePickerPositionerState, DatePickerRootEmits, DatePickerRootProps, DatePickerRootSharedProps, DatePickerTriggerProps, DatePickerTriggerState, PlainDate, PositionerProps, RenderSlotProps, Side, OpenChangeDetails, OverlayActions, OverlayPortalProps, OverlayRootEmits, OverlayRootProps |
@fragiola/primitives-angular/date-picker | DatePickerRoot, Align, CalendarOptions, CalendarValue, ChangeDetails, ChangeReason, createDatePicker, DATE_PICKER, DatePickerComponent, DatePickerInputs, DatePickerPopup, DatePickerPopupState, DatePickerPortal, DatePickerPositioner, DatePickerPositionerState, DatePickerRootBase, DatePickerState, DatePickerTrigger, DatePickerTriggerData, DatePickerTriggerState, injectDatePicker, OpenChangeEvent, PickerComponent, PlainDate, Side, ValueChangeEvent, OpenChangeDetails, OverlayActions, OverlayPortalOptions |