Skip to content
Hazine

Two Field Date Range Picker

Start and end date inputs joined in one frame that share a two month popover calendar. Use for report periods, leave requests and campaign dates where typing is as common as picking.

How it differs. Two typed fields over one calendar: the focused field decides which end a click sets, a dashed band previews it, a pick on the wrong side swaps the ends, and one message reports cross field errors.

Install

pnpm dlx shadcn@latest add @hazine/date-range-two-fields

Adds 3 files, 2 shadcn primitives (calendar, popover), 1 Hazine item (@hazine/use-controllable-state), and 1 package (lucide-react).

First time? Add the registry to components.json
{
  "registries": {
    "@hazine": "https://api.hazine.dev/r/{name}.json"
  }
}

Needed once per project. Items resolve each other through the @hazine namespace.

Props16

value
DateRange
A typed end may come before the start. The fields flag it, the value is not reordered.
defaultValue
DateRange
onValueChange
(value: DateRange) => void
open
boolean
defaultOpen
boolean = false
onOpenChange
(open: boolean) => void
min
string
Earliest and latest day that can be chosen, as ISO dates.
max
string
today
string
The day marked as today, as an ISO date. Defaults to the device date.
locale
string = "en-US"
disabled
boolean = false
readOnly
boolean = false
error
string
A message from outside, such as a server check. Marks both fields invalid.
startName
string
Names of two hidden inputs that submit the ISO dates with a form.
endName
string
labels
Partial<DateRangeTwoFieldsLabels>
Overrides for every string the component renders or speaks: field names, button names, the calendar's month buttons and day names, the hint, the day count and the four error messages.

Also accepts every prop of Omit< React.ComponentProps<"div">, "defaultValue" | "onChange" | "role" >.

Accessibility

Pattern
Form with labelled fields, Grid (APG, opens in a new tab)
Keyboard
Keyboard support for Two Field Date Range Picker
KeyEffect
TabMoves through start field, end field, clear button and calendar button
Arrow Down in a fieldCommits typed text, opens the calendar and moves focus to that field's date in the grid, or to today when the field is empty. That field is the end the next pick sets
Enter in a fieldCommits typed text, then submits the form as usual
EscapeCloses the calendar. From the grid, focus returns to the calendar button. With the calendar closed, discards typed text that is not committed
Enter or Space on the calendar buttonOpens the calendar and moves focus to the grid, or closes it
Tab in the calendarMoves through previous month, next month and the day grid. Past either end, closes the calendar and returns focus to the calendar button
Arrow keys in the gridMove by day or week and preview the range
Home, EndMove to the start or end of the week
Page Up, Page DownMove by month, or by year with Shift
Enter or Space on a daySets the active end, swapping the two when the day lands on the wrong side of the other end. A start pick moves on to the end, an end pick that completes the range closes the calendar and returns focus to the calendar button
Enter or Space on ClearEmpties both fields and moves focus to the start field
Screen reader

A group holding two labelled text inputs, a clear button and a calendar button. The calendar is a non-modal dialog with two date grids that mark the range through aria-selected, and it announces which end the next pick sets. Errors sit in an alert region and the day count in a status region, both described on each input. Day, month and weekday names follow the locale.

  • Announces: {count} days, {start} to {end}
  • Announces: Pick a start date
  • Announces: Pick an end date
  • Announces: Start date is not a date. Type it as {pattern}.
  • Announces: End date is too late. Pick {date} or earlier.
  • Announces: End date is before start date. Pick an end on or after the start.
Reduced motion
No motion of its own. Colour transitions only. The popover primitive keeps the host's open and close animation.
Checked
Not checked yet. Automated results appear here once CI has run.

Dependencies4

  • calendar
  • popover
  • @hazine/use-controllable-state
  • lucide-react

Filled chips are registry items the CLI adds for you. Outlined chips are npm packages.

Tokens shipped0

None. The item is styled by the tokens your theme already has.