Date range picker
A field that opens a calendar for a range: hold a day and drag (turning months at the edge), shortcuts, a draft until Apply, length limits and a rolling "5 nights".
npx @swipeui/cli add date-range-pickerWhen to use it
- Booking stays, rentals or trips with a first and last day, counted in nights.
- Report and analytics filters, with shortcuts like Last 7 days.
- Leave requests and campaigns where some days in between can't be chosen, or the length is limited.
When not to use it
- A single date. Use Date picker.
- A calendar that stays on screen. Use Calendar with `mode="range"`.
- Relative periods only (Day, Week, Month). Use Segmented control.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add date-range-picker- Adds
components/swipeui/ui/date-range-picker.tsx,components/swipeui/ui/use-date-range-picker.tsand 19 shared helpers. - Installs react-native-gesture-handler, react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-svg, react-native-safe-area-context, @expo/ui, @gorhom/bottom-sheet, expo-blur. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { DateRangePicker } from '@/components/swipeui/ui/date-range-picker';
<DateRangePicker label="Travel dates" />;Sheets need SheetProvider near the app root; on wide screens the calendar opens in a popover, which needs OverlayProvider.
Examples
A stay counted in nights, at least two and at most three weeks, that never crosses a booked night:
<DateRangePicker
label="Stay"
lengthUnit="nights"
minLength={2}
maxLength={21}
isDateDisabled={isBooked}
/>Report shortcuts (Today, Last 7 days, Last 30 days, This month, Year to date) that keep the range as soon as it's finished:
<DateRangePicker label="Report period" presets="standard" commit="instant" clearable />Your own shortcuts:
<DateRangePicker
label="Compare with"
presets={[{ label: 'Launch week', value: { start: launch, end: addDays(launch, 6) } }]}
/>API reference
DateRangePickerProps
| Prop | Type | Default | Description |
|---|---|---|---|
label | | — | The visible and spoken name. An empty string hides it visually. |
value? | | — | The chosen range (controlled). |
defaultValue? | | | The range it starts with (uncontrolled). |
onValueChange? | | — | Reports a range once it's applied (or finished, with |
placeholder? | | | Shown, muted, when nothing is chosen. |
presets? | | | Shortcuts above the calendar: your own, |
presetLayout? | | | Shortcuts as a scrolling row of chips, a side list, or |
commit? | | |
|
closeDelay? | | | With |
months? | | | Months side by side: one, two, or |
presentation? | | | Where the calendar opens: a sheet, a popover under the field, or |
minDate? | | — | The earliest day that can be chosen. |
maxDate? | | — | The latest day that can be chosen. |
isDateDisabled? | | — | Your own rule for days that can't be chosen; ranges never cross one. |
minLength? | | | The shortest range, in |
maxLength? | | | The longest range, in |
lengthUnit? | | | How length is counted and shown: |
showLength? | | | ★ The footer's rolling length ("5 nights"). |
caption? | | | "From … to …" under the calendar once a range is finished. |
paintSelect? | | | ★ Hold a day and drag to draw the range; the tint follows the finger. |
edgePaging? | | | ★ While holding, resting against the calendar's side edges turns the month. |
weekStartsOn? | | | First day of the week, Sunday = 0, or |
firstDayOfWeek? | | — | 1.x name for |
locale? | | | Locale for month and weekday names and the field's dates. |
formatValue? | | | Your own field text for a range. |
rollValue? | | | The field's text rolls up for a later range and down for an earlier one. |
clearable? | | | A clear button inside the field while a range is chosen. |
open? | | — | Whether the calendar is open (controlled). |
defaultOpen? | | | Open on mount (uncontrolled). |
onOpenChange? | | — | Reports opening and closing. |
helper? | | — | Supporting text under the field. |
error? | | — | Validation message. A new one shakes the field once and plays an error haptic. |
success? | | — | Confirmation text; replaces the helper. |
status? | | | Validation state shown on the field. |
required? | | | Marks the field required; "Required" is spoken. |
requiredIndicator? | | | How a required field is marked. |
optionalIndicator? | | | Show "Optional" after the label. |
disabled? | | | Prevents opening and clearing. |
disabledStyle? | | |
|
appearance? | | | The field's surface. |
size? | | |
|
shape? | | |
|
labelPlacement? | | | Where the label sits: above, inside at the top ( |
focusRing? | | | The ring and halo shown while open. |
leadingIcon? | | — | A leading icon in the field: a node, or a function given the state colour and size. |
messages? | | | Built-in strings, for translation. |
haptics? | | | Haptics: a switch, or per part ( |
motion? | | | Field, panel, calendar and footer motion. |
className? | | — | Classes on the field. |
style? | | — | Field style. |
testID? | | — | The field's identifier. Parts append |
Ranges are { start?, end? } of local days. onValueChange reports a finished range, or {} after clearing.
Composition and behavior
- The trigger is a field: filled by default, a compact range ("Nov 12 – 18", in the locale's order, with years when the range leaves this year), an optional leading icon and a chevron that turns while open, with the focus ring. The text rolls up for a later range and down for an earlier one.
- Tap the first day, then the last. A last day before the first swaps them, and a range stops before a day that can't be chosen.
- ★ Hold a day and drag: a tinted highlight follows the finger and lifting sets the last day. Rest the finger on the calendar's side edge to turn the month without lifting; the range keeps following.
- Once a range is finished, "From … to …" appears under the calendar and the footer rolls its length in days or nights. The first day, then the finished range and its length, are announced.
- With commit
apply, the range is a draft until Apply; Cancel, Escape or a tap outside discard it. Withinstant, a finished range is kept at once and the panel closes after closeDelay. - minLength keeps Apply off until the range is long enough and says why; maxLength stops a drag or a second tap at the longest range, with a limit tick.
- Shortcuts are a scrolling row of chips on phones and a side list when the panel is wide; two months show side by side from 600pt.
Date range picker settings
| Prop | Does | Default |
|---|---|---|
| presets | Your own shortcuts, standard or none | none |
| presetLayout | auto (chips, side list when wide), row or list | auto |
| commit / closeDelay | apply draft or instant (ms before closing) | apply, 400 |
| months | auto, 1 or 2 side by side | auto |
| presentation | auto (sheet on phones), sheet or popover | auto |
| lengthUnit | Count days or nights | days |
| minLength / maxLength | Shortest and longest range, in the unit | 1, unlimited |
| showLength | ★ The footer's rolling length | true |
| caption | "From … to …" under the calendar | true |
| paintSelect / edgePaging | ★ Hold and drag; turn months at the edge | true, true |
| minDate / maxDate / isDateDisabled | Days that can't be chosen | none |
| weekStartsOn | First weekday (Sunday = 0) or locale | 1 (Monday) |
| formatValue | Your own field text | locale "Nov 12 – 18" |
| rollValue / clearable | Rolling field text; a clear button | true, false |
| appearance / size / shape | Field look: filled…, sm/md/lg, preset/pill | filled, md, preset |
| labelPlacement / leadingIcon | above, inset or hidden; an icon | above, none |
| helper / error / success | Messages under the field | none |
| required / disabled | Required mark; no opening or clearing | false |
| haptics | All, or { select, detent, limit, clear } | select, detent, limit |
| messages | Built-in strings (and calendar), for translation | English |
| motion | A local motion feel or override | the app's feel |
Behavior and gestures
- Tap the field to open the calendar: a sheet on phones, a popover under the field on wide screens (`presentation`).
- Tap the first day, then the last; a last day before the first swaps them, and a range stops before a day that can't be chosen.
- ★ Hold a day (350 ms) and drag: a tinted highlight follows the finger, and lifting sets the last day. Resting on the calendar's side edge turns the month without lifting (`paintSelect`, `edgePaging`).
- Once a range is finished, "From … to …" appears under the calendar and the footer rolls its length (`lengthUnit` days or nights).
- Shortcuts (`presets`, or `standard`) fill the range in one tap and turn the calendar to it: a scrolling row of chips on phones, a side list when the panel is wide.
- Apply keeps the range; Cancel, Escape or a tap outside discard the draft (`commit="apply"`). With `commit="instant"` a finished range is kept at once and the panel closes after `closeDelay`.
- `minLength` keeps Apply off until the range is long enough and says so; `maxLength` stops a drag or a second tap at the longest range with a limit tick.
- With `clearable`, a clear button inside the field empties it.
Accessibility
- The field is a button named "Label: range" (or the placeholder) that reports expanded; helper or error text is its hint.
- Each day reads its full date and whether it's chosen, inside the range or unavailable.
- The first day is announced, then the finished range with its length in the unit ("From Nov 9 to Nov 14, 5 nights"); shortcuts announce the same way.
- Shortcuts report `selected` when the draft matches them. Apply is named "Apply <label>" and is disabled until the range is valid; the footer note is a polite live region.
- Every gesture has a tap path: tap the first and last day, and use the header buttons to turn months.
Motion
- Uses the
select,toggle,morph,number,overlay,dragandpressmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - The sheet or popover opens on the overlay role; the ring and chevron turn on the toggle role.
- Inside, the calendar's highlight, range bars and months move on its own roles (select, toggle, overlay, drag).
- The field's text rolls up for a later range and down for an earlier one on the morph role; "From … to …" rises in on morph; the length rolls its digits on the number role.
- Reduce Motion: the text and caption fade, the length swaps, and the calendar jumps instead of sliding; haptics stay.
Performance
- The calendar mounts only while the panel is open. Drags run on the UI thread with one tick per day crossed.
- Dates are counted on calendar fields (no millisecond maths), so ranges are right across daylight-saving changes.
Notes for AI
- Ranges are `{ start?, end? }` of local days; `onValueChange` reports a finished range (or `{}` after clearing).
- Pass presets as `{ label, value: { start, end } }`, or `presets="standard"` for Today, Last 7 days, Last 30 days, This month and Year to date (names through `messages.presetNames`).
- `minLength` and `maxLength` count in `lengthUnit`: a 2-night minimum is `minLength={2} lengthUnit="nights"`.
- Popovers need `OverlayProvider` at the app root; sheets need `SheetProvider`.
- Strings (including the calendar's, under `messages.calendar`) are translatable; month names fall back to English on engines without `Intl` month names.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.