DatePicker
11 partsA single-date picker that pairs a popover-anchored calendar with an optional
trigger, field, and hidden form input. Owns the selected date, placeholder
month, and open state, and provides both date-picker and calendar context to
its parts. Use it when you need a compact, accessible "pick one date" control
(e.g. a form field) rather than an always-visible Calendar.
Demo
Anatomy
Import the parts and compose them. Each part forwards attributes to its underlying element.
import {
DatePickerRoot,
DatePickerTrigger,
DatePickerAnchor,
DatePickerPortal,
DatePickerContent,
DatePickerArrow,
DatePickerClose,
DatePickerCalendar,
DatePickerField,
DatePickerFieldRoot,
DatePickerFieldSegment,
} from '@robonen/primitives/display/date-picker';
<DatePickerRoot>
<DatePickerTrigger />
<DatePickerAnchor />
<DatePickerPortal />
<DatePickerContent />
<DatePickerArrow />
<DatePickerClose />
<DatePickerCalendar />
<DatePickerField />
<DatePickerFieldRoot />
<DatePickerFieldSegment />
</DatePickerRoot>API Reference
DatePickerRoot
RootA single-date picker that pairs a popover-anchored calendar with an optional trigger, field, and hidden form input. Owns the selected date, placeholder month, and open state, and provides both date-picker and calendar context to its parts. Use it when you need a compact, accessible "pick one date" control (e.g. a form field) rather than an always-visible `Calendar`.
| Prop | Type | Description |
|---|---|---|
defaultOpen? | boolean | Uncontrolled initial open state. |
modal? | boolean | Modal popover (traps focus + blocks outside pointer). |
name? | string | Hidden form input name for submission. |
id? | string | Id forwarded to the focusable form control / first segment. |
required? | boolean | Marks the form control as required for native constraint validation. |
valueFormat? | 'iso' | ((d: Date) => string) | Format used to serialize the hidden input value. |
closeOnSelect? | boolean | Close popover on selection. |
preventDeselect? | boolean | Keep the current value selected when the already-selected date is picked again (otherwise re-selecting clears it). |
granularity? | Granularity | Smallest unit the field edits. 'day' is date-only; 'hour'/'minute'/
'second' add time segments and preserve the time-of-day. |
hourCycle? | HourCycle | Hour cycle for the time segments (12 or 24). Inferred from locale if omitted. |
open? | boolean | Two-way bound value (v-model:open). |
modelValue? | Date | undefined | Two-way bound value (v-model). |
placeholder? | Date | Two-way bound value (v-model:placeholder). |
| Event | Payload |
|---|---|
update:open | [value: boolean] |
update:modelValue | [value: Date | undefined] |
update:placeholder | [value: Date] |
DatePickerTrigger
TriggerThe button that toggles the picker popover open and closed. Acts as the Popper anchor (unless a custom `DatePickerAnchor` is present) and carries the dialog-related ARIA wiring (`aria-haspopup`, `aria-expanded`, `aria-controls`).
No props or events — renders its element and forwards attributes.
DatePickerAnchor
AnchorOptional custom anchor for positioning the popover against an element other than the trigger (e.g. a field or input group). When present, the trigger stops acting as the anchor and the content is positioned relative to this.
No props or events — renders its element and forwards attributes.
DatePickerPortal
PortalTeleports the popover content into a different part of the DOM (the body by default) so it escapes overflow/stacking-context clipping. Wrap `DatePickerContent` with it when the picker lives inside a scrolled or transformed container.
No props or events — renders its element and forwards attributes.
DatePickerContent
ContentThe popover panel that holds the calendar. Handles Popper positioning, presence (mount/unmount on open), focus trapping/restoration, and dismissal via Escape or outside interaction. Renders only while open unless `forceMount` is set.
| Prop | Type | Description |
|---|---|---|
forceMount? | boolean | Keep mounted for CSS exit animations. |
DatePickerArrow
ArrowAn optional arrow rendered inside `DatePickerContent` that points back at the trigger/anchor. Purely decorative; place it as a child of the content.
No props or events — renders its element and forwards attributes.
DatePickerClose
CloseA button that closes the picker popover when clicked. Render it inside `DatePickerContent` (e.g. a "Done" or dismiss action).
No props or events — renders its element and forwards attributes.
DatePickerCalendar
CalendarA styling wrapper for the calendar grid rendered inside the popover. The calendar subparts (`DatePickerGrid`, `DatePickerCell`, etc.) consume the calendar context provided by `DatePickerRoot`; this element just groups and labels them with a `data-primitives-date-picker-calendar` hook.
No props or events — renders its element and forwards attributes.
DatePickerField
FieldA text input that renders the selected date and, when `editable`, lets users type a date that is parsed and committed back to the picker on blur/Enter. Aliased as `DatePickerInput`; defaults to a read-only display of the value.
| Prop | Type | Description |
|---|---|---|
editable? | boolean | Allow typing into the field. |
format? | Intl.DateTimeFormatOptions | Display format for the rendered value. |
placeholderText? | string | Placeholder text shown when no value is selected. |
DatePickerFieldRoot
FieldRootA segmented date field: a `role="group"` of individually-focusable `role="spinbutton"` segments (`DatePickerFieldSegment`) that edit one part of the date each. It reads the picker's value, placeholder, locale, granularity, and hour cycle from `DatePickerRoot`, and commits a complete date back to the picker. This is the accessible, keyboard-driven alternative to the plain `DatePickerField` text input. The default slot receives the ordered `segments` descriptors (including literals) and the current `modelValue`, so the consumer renders a `DatePickerFieldSegment` per segment.
No props or events — renders its element and forwards attributes.
DatePickerFieldSegment
FieldSegmentA single segment of a `DatePickerFieldRoot`. Editable parts (`day`, `month`, `year`, `hour`, `minute`, `second`, `dayPeriod`) render as a focusable `role="spinbutton"` with `aria-valuemin/max/now/valuetext`; `literal` parts render as inert separators. Supports arrow increment/decrement, numeric type-ahead with auto-advance, Backspace to clear, and `a`/`p` for AM/PM.
| Prop | Type | Description |
|---|---|---|
part | SegmentPart | The date part this segment edits. |