GhostDatePicker
GhostDatePicker combines ordinary text entry with an anchored modal calendar for a single date or an inclusive date range. It follows the WAI-ARIA APG Date Picker Dialog pattern. Import the parts from @ghostvue/themes to use the default styles, including the calendar recipe. The themed inputs and trigger are one medium control tall, so they line up with GhostInput and GhostButton, and every target grows to 44px on coarse pointers. The themed surface has one header row (the month title, then the previous, next, and close buttons) and shows its status line under the month only while it has text.
Values are date-only CalendarDate objects (years 0001–9999), the same type GhostCalendar uses. JavaScript Date, timestamps, time zones, and date-time values are not accepted.
| Part | Renders | Purpose |
|---|---|---|
GhostDatePicker | hidden form inputs only | State, validation, and form-value owner |
GhostDatePickerInput | <input type="text"> | Typed entry for part="single", "start", or "end" |
GhostDatePickerTrigger | <button type="button"> | Opens the calendar dialog |
GhostDatePickerContent | role="dialog" with aria-modal="true" | Positioned modal surface with a Close control |
GhostDatePickerCalendar | GhostCalendar header, navigation, grid | Calendar bound to the picker; default content of the slot |
Book a trip
Type a departure and return date, or open Choose trip dates and select both in the calendar. The example starts with a December itinerary you can revise.
Choose departure and return dates with a themed range picker and a labeled field for each endpoint.
Basic use
Typing never changes the value until the text is committed with Enter or by leaving the input. Text that is invalid or incomplete stays visible with an error and never replaces the committed value. Escape in an edited input restores the committed text.
By default the input accepts strict ISO YYYY-MM-DD: no whitespace, zero padding required, and impossible dates such as 2023-02-29 are rejected rather than adjusted.
today and SSR
The picker never reads the client clock. Pass today for "today" styling and as the focus fallback when the picker opens empty; otherwise an empty picker opens on defaultVisibleMonth, then January 2024. Computing today on the server and passing it down keeps SSR and hydration identical:
import { CalendarDate } from '@ghostvue/vue'
const now = new Date()
const today = new CalendarDate(
now.getFullYear(),
now.getMonth() + 1,
now.getDate(),
)Range selection
The trip booking example shows a themed date range.
Set selection-mode="range" and render two inputs, one with part="start" and one with part="end". Moving focus between the two inputs keeps both drafts; the pair is validated when focus leaves both or on Enter. Typed endpoints are never swapped: an end before the start is an ordering error.
In the calendar, the first activation starts a pending range (the status line says "Choose an end date") and the second activation commits both endpoints at once, sorted, and closes the dialog. Activating the same day twice commits a one-day range. Escape, Close, or an outside click discard the pending range.
Range inputs with GhostField
Give each endpoint its own GhostField (and so its own id and label), and name the pair with a group. Never bind one GhostFieldControl id to both inputs.
<div role="group" aria-labelledby="trip-label">
<span id="trip-label">Trip dates</span>
<GhostDatePicker v-model="trip" selection-mode="range" name="trip">
<GhostField>
<GhostFieldLabel>Departure</GhostFieldLabel>
<GhostFieldControl v-slot="field">
<GhostDatePickerInput v-bind="field" part="start" />
</GhostFieldControl>
</GhostField>
<GhostField>
<GhostFieldLabel>Return</GhostFieldLabel>
<GhostFieldControl v-slot="field">
<GhostDatePickerInput v-bind="field" part="end" />
</GhostFieldControl>
</GhostField>
<GhostDatePickerTrigger />
<GhostDatePickerContent />
</GhostDatePicker>
</div>disabled, invalid, and required from GhostFieldControl combine with the root's own state.
Picker errors flow into the field that holds each input, so a GhostFieldError shows them without extra wiring. An error about one endpoint goes to that endpoint's field. An error about the whole range, such as a validate-range rejection, goes to the start field only, so it is announced once. See Use with GhostForm.
Controlled value and open state
Controlled value and open state with an explicit clear action.
v-model holds a CalendarDate in single mode, a start and end pair in range mode, or null when empty. Leave it unbound for uncontrolled use from the default value; a bound null is a controlled empty value. The picker emits proposals and shows whatever the parent keeps: an ignored proposal restores the parent's value in the input and the hidden form inputs. Equal values are not re-emitted. A changed external value replaces any typed drafts and cancels a pending range.
v-model:open is independent. The effective state is open && !disabled && !readonly: becoming disabled or readonly requests close and removes the dialog at once, and re-enabling follows the open prop again. If a parent ignores a close request, the dialog stays open.
The root slot exposes { value, open, pending, errors, clear, openCalendar, close } for custom controls such as a Clear button.
Validation, forms, and reset
Required range with bounds, validateRange rejecting interior unavailable dates, native submit and reset.
The minimum and maximum dates are inclusive, and is-date-disabled marks unavailable endpoints (they stay focusable in the grid but cannot be selected). Both endpoints of a range are checked. Dates inside a range are allowed even when unavailable, matching GhostCalendar. Reject them, or enforce a maximum stay, with validate-range. Cap the length before scanning so the check stays bounded:
function validateStay(range: GhostDatePickerRange): string | null {
const nights = range.end.compare(range.start)
if (nights > 14) return 'Stays are limited to 14 nights'
for (let offset = 0; offset <= nights; offset += 1) {
if (isBooked(range.start.add({ days: offset }))) {
return 'This stay includes booked nights'
}
}
return null
}A rejected second calendar activation keeps the first endpoint and the dialog open, and announces the message.
Form behavior:
name="due"submitsdue=2026-11-17. An empty value submits an empty string.- In range mode,
name="stay"submitsstay[start]andstay[end]. The start and end name props override each endpoint's name. - Hidden inputs carry only the committed ISO value, never typed text, so display formatting never changes what is submitted. Use the root
formprop for an external<form>;nameandformon an input are ignored. - Native constraint validation stays in sync while typing: an uncommitted draft ("Confirm this date"), an invalid draft,
required, orinvalidblocks submission, includingform.requestSubmit(). Disabled pickers are omitted and not validated; readonly pickers submit and are exempt, as with native inputs. - If the form is submitted while the calendar is open, the error summary inside the dialog receives focus instead of the inert input.
- A native form reset restores
default-value(uncontrolled) or the current props (controlled, no event), clears drafts and errors, and closes the calendar. A cancelled reset is respected.
Each error carries a stable code. Localize the messages with validation-message, which receives the error.
| Code | Raised when |
|---|---|
parse | Typed text is not a valid date in the current format. |
incomplete | Only one endpoint of a range is filled. |
min | A date is before the minimum. |
max | A date is after the maximum. |
unavailable | An endpoint is marked unavailable. |
range-order | A typed end date is before the start date. |
range-validation | Your range validator rejects the range. |
required | A required picker is empty. |
external-invalid | The invalid prop is set. |
configuration | The minimum is after the maximum, or the value has the wrong shape. |
uncommitted | Typed text has not been committed yet. |
The picker never infers the selection mode from the value, so a range value in single mode, or the reverse, is a configuration error.
Use with GhostForm
Date range inside GhostForm with a maximum stay; the picker's reason shows in the field error and blocks submit.
Put each input in a GhostField, as in Range inputs with GhostField. Picker errors then flow into those fields and the surrounding GhostForm automatically. You don't need to render slot errors beside the field; if you already do, remove that copy so the message is not shown twice.
- One message per field. While the picker rejects the text on screen (an unparsable date, a date out of bounds, a rejected range, an uncommitted draft), the field shows the picker's reason, for example "Stays are limited to 14 nights", instead of the schema's message for an empty value. Once the text is fixed or
Escaperestores it, the form's message returns if it still applies. Forrequiredandinvalid, the form's own message wins when it has one. - Routing. An endpoint error goes to the field holding that input. A range error goes to the start field, or to the end field when the start input is not in a field. Errors shown only inside the open calendar stay there. Disabled and readonly pickers report nothing.
- Announcements. The field's
GhostFieldErroris the only live region. An input whose field shows its error links that error instead of the picker's own description. Without aGhostFieldError, or with:invalid="false"on the field, the input keeps the picker's description. - Submit. Picker errors block submit and count in
isInvalid,fieldErrors,getFieldError, andissues(after schema issues, with the field's name aspath). A submit attempt,validate(), orvalidateField()reveals an uncommitted draft ("Confirm this date") andrequired, andfocusInvalidOnSubmitmoves focus to the first invalid input. - Ownership. The picker owns its errors:
clearErrorsandsetFieldErrorsdo not remove them. An imperativereset()keeps typed drafts, so an error about visible text stays; a native reset clears both.
The schema still sees only committed values. Keep date values in shallowReactive (or shallowRef): CalendarDate has private fields, so a deep reactive proxy breaks it.
Errors also flow into a GhostField without a form, or without a name, which makes the field invalid and shows the message in GhostFieldError. A picker outside any GhostField behaves as before.
Custom formats and locale
Consumer parse and format callbacks for DD.MM.YYYY with an en-GB calendar.
Custom parse and format callbacks are synchronous and pure, and receive the locale and the input part. The parser returns null for invalid text (empty text is handled before it is called). The two must round-trip each other. A parser that throws marks the draft invalid; a formatter that throws falls back to ISO and logs GHOST004 in development. Custom callbacks never bypass bounds or availability checks. Update the format hint so the linked format description matches.
The locale prop localizes calendar month and day labels. Built-in instructions and messages are English. Localize error messages with validation-message, the close button and range instruction with the content's label props, and the trigger and dialog names with native aria-label.
Right-to-left
Date picker in an RTL container; arrow keys follow reading direction.
Arrow keys follow reading direction inside an RTL container.
Inside a dialog
Date picker in a modal dialog; Escape closes only the top layer.
The calendar is its own modal layer: Escape closes only the top layer and returns focus to the trigger inside the outer dialog. Escape in an edited input reverts the text without closing the outer dialog.
The themed calendar scrolls internally when there is too little room to display it at full height alongside the input. Moving focus reveals the focused control within the calendar's scroll area.
Content placement
The content anchors to the single or start input (or the trigger when there is no input). It opens below the anchor, aligned to its start edge, and flips and shifts to stay in view. Its placement, offset, positioning strategy, and portal target are props; see the content API. Modal semantics are fixed: the background is inert, focus is trapped, and the page does not scroll while it is open. GhostPopover itself stays non-modal.
Without a slot, the content renders GhostDatePickerCalendar. Provide the slot to add help text, or pass GhostCalendar* parts to GhostDatePickerCalendar for a custom header.
Accessibility
- Inputs are native text fields (not combobox or spinbutton) linked to the format hint and current errors with
aria-describedby. Inside aGhostFieldwith aGhostFieldError, the input links the field's error for the errors that field shows, so each message is announced once. - The trigger is a native button with
aria-haspopup="dialog"that reports whether the calendar is expanded and which dialog it controls. Its default name includes the selected date or range; override it witharia-labeloraria-labelledby. - On open, focus moves to the selected date (or range start), else
todaywhen it is in the visible month, else the first day of that month, clamped to the bounds. If no date can take focus, the Close button does. - Closing restores focus to the trigger, or to the input when the trigger is gone or disabled.
In the calendar grid:
| Key | Behavior |
|---|---|
| Arrow keys | Move by day and week (reversed in RTL). |
Home / End | Move to the start or end of the week. |
Page Up / Page Down | Move by month. |
Shift + Page Up / Page Down | Move by year. |
Enter / Space | Select the focused date. |
Tab | Cycles through the dialog with one stop in grid. |
Automated axe checks run with the dialog open and closed. Manual screen-reader review is still required before this component is marked stable.
Advanced: headless customization
Import from @ghostvue/vue when you supply the input, trigger, and calendar styles. The examples below show the same positioning and keyboard behavior with custom CSS.
The headless layer positions the calendar surface but paints nothing. The headless examples share one consumer stylesheet on the date-picker-demo__* classes: an opaque, layered surface, a 7-column month grid whose weekday header lines up with the weeks, and styles for each day state. Copy it once per app, or use the themed parts.
Today, selected, in-range, outside-month, and unavailable days are styled from data-today, data-state, data-outside-month, and aria-disabled.
Single date with custom styles
Single date with typed ISO entry and an anchored modal calendar.
Date range with custom styles
Start and end inputs in a named group; two calendar activations commit atomically.
API
See the specification and the generated component references. Manifests live in packages/vue/manifests/ghost-date-picker*.manifest.json and packages/themes/manifests/ghost-date-picker.manifest.json.
GhostDatePicker
| Prop | Type | Default | Description |
|---|---|---|---|
defaultOpen | boolean | false | Initial uncontrolled open state. |
defaultValue | GhostDatePickerValue | null | Initial uncontrolled value and uncontrolled form-reset target. |
defaultVisibleMonth | CalendarDate | — | Month shown when the picker opens empty. |
disabled | boolean | false | Blocks all interaction and closes the calendar. |
endName | string | — | Range end submission name override. |
form | string | — | External <form> id for submission, validation, and reset. |
format | GhostDatePickerFormat | — | Synchronous display formatter; defaults to ISO YYYY-MM-DD. |
formatHint | string | "YYYY-MM-DD" | Format description linked to every input. |
invalid | boolean | false | Consumer-supplied invalid state (external-invalid). |
isDateDisabled | ((date: CalendarDate) => boolean) | — | Unavailable endpoint dates (focusable, not selectable). |
locale | string | "en-US" | Calendar and formatting locale. |
maxValue | CalendarDate | — | Inclusive upper bound. |
minValue | CalendarDate | — | Inclusive lower bound. |
modelValue | GhostDatePickerValue | — | Controlled committed value; undefined is uncontrolled, null is controlled empty. |
name | string | — | Form name: name (single) or name[start] / name[end] (range). |
open | boolean | — | Controlled requested open state. |
parse | GhostDatePickerParse | — | Synchronous parser; defaults to strict ISO YYYY-MM-DD. |
readonly | boolean | false | Keeps text focusable and selectable but prevents editing, clearing, and opening. |
required | boolean | false | Native required constraint on an empty committed value. |
selectionMode | GhostDatePickerSelectionMode | "single" | 'single' or 'range'; fixed for the instance (remount with a new key). |
startName | string | — | Range start submission name override. |
today | CalendarDate | — | Explicit current date for SSR-safe "today" styling and focus fallback. |
validateRange | GhostDatePickerValidateRange | — | Whole-range business validation returning an error message or null. |
validationMessage | ((error: GhostDatePickerError) => string) | — | Localizes built-in error messages. |
weekStartsOn | GhostDatePickerWeekday | — | Week start override (Sunday = 0). |
| Slot | Slot props | Description |
|---|---|---|
default | clear: () => void, close: () => void, errors: GhostDatePickerError[], open: boolean, openCalendar: () => void, pending: boolean, value: GhostDatePickerValue | Container content. |
@ghostvue/themes adds no props, events, or slots to the headless GhostDatePicker API, which it forwards.
GhostDatePickerInput
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Combines with the root disabled (for example from GhostFieldControl). |
invalid | boolean | false | Combines with root errors (for example from GhostFieldControl). |
part | GhostDatePickerPart | "single" | Which value this input edits; range pickers need start and end. |
required | boolean | false | Combines with the root required (for example from GhostFieldControl). |
GhostDatePickerTrigger
| Slot | Slot props | Description |
|---|---|---|
default | — | Visible trigger content. Defaults to a decorative calendar icon. |
GhostDatePickerContent
| Prop | Type | Default | Description |
|---|---|---|---|
closeLabel | string | "Close date picker" | Accessible name of the built-in Close control. |
endDateInstruction | string | "Choose an end date" | Polite instruction announced after the first range activation. |
flip | boolean | GhostPopoverFlipOptions | true | Flip to the opposite side when overflowing. |
offset | boolean | GhostPopoverOffsetOptions | 4 | Distance or axis offsets between anchor and content. |
placement | Placement | "bottom-start" | Preferred placement relative to the input (or trigger). |
portal | boolean | true | Teleport through GhostPortal when true; render inline when false. |
portalTo | GhostPortalTarget | "body" | Teleport target when portal is true. |
shift | boolean | GhostPopoverShiftOptions | true | Shift along the cross axis to stay in view. |
strategy | Strategy | "absolute" | CSS positioning strategy. |
| Slot | Slot props | Description |
|---|---|---|
default | — | Calendar and optional help/error content. Defaults to GhostDatePickerCalendar. |
GhostDatePickerCalendar
| Slot | Slot props | Description |
|---|---|---|
default | — | Custom GhostCalendar* part composition. Defaults to a header with previous/next month buttons and heading, followed by the grid. |