Skip to content

DateRangePicker ​

A Calendar in range mode, behind a button. It is the same shell as DatePicker, and deliberately so: the two differ in what they collect, not in how they behave. Both close on completion, both return focus to the trigger, both format through Intl, both post ISO dates.

The one difference is when to close. A single date is done in one click; a range is not done until the second, so the popover stays open between them — closing on the first click and reopening for the second makes the control feel broken. The trigger reads Mar 14, 2026 — … while the second end is missing.

Two hidden inputs rather than one comma-joined field: a server reading from and to separately never has to split a string, and an empty to is unambiguous.

sh
ream nebula:add date-range-picker

Organism · organisms/DateRangePicker.ts · Button, Calendar, DatePicker

Usage ​

ts
import { DateRangePicker } from '@c9up/nebula'

DateRangePicker({ name: 'stay' })

Inside a <form>, this posts stay_from=2026-07-04 and stay_to=2026-07-11, each empty until its end is picked.

Examples ​

Following a signal ​

ts
import { signal } from '@c9up/aurora'
import { type DateRange } from '@c9up/nebula'

const stay = signal<DateRange | undefined>(undefined)

DateRangePicker({ value: stay, onValueChange: stay })

Without value the picker keeps the span itself, starting from defaultValue. A value that reads undefined hands the display back to that own state, so it shows the last span picked rather than the placeholder.

Acting on a complete span ​

onValueChange fires on both clicks — to is absent after the first, which is what lets a bound signal show the half-picked span. Code that needs both ends waits for to:

ts
DateRangePicker({
  name: 'stay',
  min: new Date(),
  onValueChange: (range) => {
    if (range.to !== undefined) quote(range.from, range.to)
  },
})

The span follows the Calendar's rules: a second click before the first starts again, and a click after a complete span starts a new one.

In another language ​

ts
DateRangePicker({
  name: 'stay',
  locale: 'fr-CH',
  placeholder: 'Choisir les dates',
  labels: { dialog: 'Choisir une période', previousMonth: 'Mois précédent', nextMonth: 'Mois suivant' },
})

API ​

DateRangePicker ​

PropTypeDefaultDescription
namestring—Base name of the hidden inputs — 'stay' posts stay_from and stay_to.
valueReactive<DateRange | undefined>—The chosen span, when you hold it.
defaultValueDateRange—The starting span, when the picker holds it.
placeholderstring'Pick a date range'The trigger's text while nothing is chosen.
minDate—Earliest day that can be chosen.
maxDate—Latest day that can be chosen.
disabledReactive<boolean>falseDisables the trigger.
invalidReactive<boolean>falseSets aria-invalid on the trigger.
localestringthe browser'sThe trigger's date format and the calendar's names.
labelsPartial<DatePickerLabels>{ dialog: 'Choose a date range', previousMonth: 'Previous month', nextMonth: 'Next month' }The popup's accessible name and the calendar's arrows.
classReactive<string>—Merged into the root's classes.
onValueChange(range: DateRange) => void—On both clicks — to is absent after the first. Local midnight.

DateRange is { readonly from: Date; readonly to?: Date }; DatePickerLabels is described on DatePicker.

Accessibility ​

As DatePicker: the trigger is a <button> with aria-haspopup="dialog", aria-expanded and aria-controls; the popup is role="dialog" named by labels.dialog; it opens on the selected start — or today — rather than on the month arrow, keeps focus inside while open, and returns it to the trigger when a complete span or Escape closes it — a click outside leaves focus where that click puts it.

KeyAction
Enter / Space on the triggerOpens or closes the popup.
Tab / Shift+TabMoves between the month arrows and the grid, wrapping inside the popup.
EscapeCloses the popup, keeping a half-picked span.
Arrows, Page Up/Page Down, Home/EndAs in the Calendar.
Enter / Space on a dayFixes one end; the second closes the popup.

The placeholder, the popup's name and the two arrow names are built-in English: placeholder and labels replace them — see languages.