Skip to the content
human-kit design
25 — Pickers

Date Range Picker

Two dates, a start and an end, typed part by part or picked from two months.

mmddyyyy
mmddyyyy

Installation

pnpm dlx @human-kit/design add date-range-picker
npx @human-kit/design add date-range-picker
yarn dlx @human-kit/design add date-range-picker
bunx @human-kit/design add date-range-picker

The command copies the files to src/lib/components/ui/date-range-picker. It also installs the packages that the files import.

Usage

<script lang="ts">
	import * as DateRangePicker from '$lib/components/ui/date-range-picker';

	let dates = $state<{ start: string; end: string } | null>(null);
</script>

<DateRangePicker.Root aria-label="Treatment dates" bind:value={dates} />

Examples

Locale

Wrap the picker in a LocaleProvider: both ends are written as the locale writes a date, and the calendars follow it. The value stays YYYY-MM-DD in every one.

11102026
11192026
10112026
19112026

Guidelines

  • Use the date range picker for a stretch with a start and an end: a treatment, a leave, the period of a report. For one day, use the date picker.
  • Keep two months side by side where there is room: a stretch that crosses the end of a month is then picked in one view. Show one with visibleMonths={1} in a narrow column.
  • Use the default variant in a form, ghost in a toolbar and underline in a form drawn with lines.
  • Rename startLabel and endLabel to what the dates mean, "Check-in" and "Check-out", when the general words read poorly.
  • In a form, give startName and endName: each date travels in a hidden input of its own.

Accessibility

  • The range is a group named by aria-label. Each date in it is a group of its own, named by startLabel and endLabel.
  • Each part of a date is a role="spinbutton": digits fill it and move on, Up and Down step it, Left and Right move between the parts.
  • In the calendar, the first press starts the range, the arrows stretch it, and Enter or Space ends it.
  • An unavailable day still takes the focus and is read as disabled, so the grid has no holes.
  • The calendar button and the month arrows are named by triggerLabel, previousLabel and nextLabel, so each can be translated.

API reference

PropTypeDefault
value{ start: string; end: string } | null

The two dates, each as YYYY-MM-DD, or null while there is no whole range. Bindable.

—
defaultValue{ start: string; end: string } | null

The range at the start, when no value is bound.

—
onChange(value: { start: string; end: string } | null) => void

Runs when the range changes, by typing or in the calendar.

—
variant'default' | 'filled' | 'ghost' | 'underline'

The look of the box, as the input has.

'default'
size'sm' | 'default' | 'lg'

The height, matched to the buttons of each size.

'default'
visibleMonthsnumber

How many months the calendar shows side by side.

2
minValuestring

The first day that can be picked, as YYYY-MM-DD.

—
maxValuestring

The last day that can be picked, as YYYY-MM-DD.

—
isDateUnavailable(date: string) => boolean

Turns off the days it returns true for.

—
openboolean

Whether the calendar shows. Bindable.

—
defaultOpenboolean

Whether the calendar starts open, when no open is bound.

false
onOpenChange(open: boolean, details: DateRangePickerOpenChangeDetails) => void

Runs when the calendar opens or closes.

—
closeOnSelectboolean

Closes the calendar once the range is complete.

true
invalidboolean

Marks both dates as refused, for a Field.Root with an error.

false
disabledboolean

Turns the picker off.

false
readonlyboolean

Shows the range and lets it be read, but not changed.

false
aria-labelstring

The name of the range as a whole.

—
aria-describedbystring

The id of the hint or the error under it, read with each date.

—
startLabelstring

The name of the first date, read aloud.

'Start date'
endLabelstring

The name of the second date, read aloud.

'End date'
startNamestring

The name of the hidden input that carries the first date in a form.

—
endNamestring

The name of the hidden input that carries the second date.

—
triggerLabelstring

The name of the calendar button, read aloud.

'Choose dates'
previousLabelstring

The name of the arrow to the month before.

'Previous month'
nextLabelstring

The name of the arrow to the month after.

'Next month'

class styles the box. The picker takes only these props: there is no passthrough of other attributes.