A booking range with rules

Hotel stay

Type the dates or open the calendar. Fully booked dates are unavailable; fewer than two nights shows an error.

Preview

Two nights minimum. 20–22 November is fully booked.

Choose at least 2 nights (you chose 1).

Example.tsx
import { DateRangePicker, parseDate, type DateValue } from '@reactloom/dates';
import { useState } from 'react';

type Range = { start: DateValue; end: DateValue } | null;

// Fixed dates keep the prerendered page and the live example identical.
const opens = parseDate('2026-11-01');
const fullyBooked = ['2026-11-20', '2026-11-21', '2026-11-22'].map((d) => parseDate(d));

export default function Example() {
  const [stay, setStay] = useState<Range>({ start: parseDate('2026-11-12'), end: parseDate('2026-11-13') });
  const nights = stay ? stay.end.compare(stay.start) : 0;
  return (
    <div style={{ width: '100%', maxWidth: 360 }}>
      <DateRangePicker
        label="Stay"
        description="Two nights minimum. 20–22 November is fully booked."
        value={stay}
        onValueChange={setStay}
        minValue={opens}
        isDateUnavailable={(date) => fullyBooked.some((d) => d.compare(date) === 0)}
        error={stay && nights < 2 ? `Choose at least 2 nights (you chose ${nights}).` : undefined}
        startName="checkIn"
        endName="checkOut"
      />
    </div>
  );
}

Typing and picking

Many date pickers only offer a calendar, which is slow for dates far away (a date of birth, last year’s report) and hard to use with a screen reader. DateRangePicker is two date fields with a calendar button:

  • Each part of a date is a spin button named by its unit. Type digits, or use ↑ and ↓ to change the focused part.
  • The order of parts and separators follows the user’s locale: 12 November 2026 is 11/12/2026 in en-US and 12.11.2026 in de-DE, with no format string to maintain.
  • Alt + ↓ or the button opens a calendar with two months; arrow keys move by day and week, Page Up/Down by month.
  • Unavailable dates stay focusable and are announced as unavailable, so people know why they cannot choose them.

Values without time-zone bugs

Values are CalendarDate objects from @internationalized/date, not JavaScript Dates. A calendar date has no time and no time zone, so 12 November stays 12 November for a user in Tokyo and a server in Virginia. Compare with a.compare(b), add with date.add({ days: 2 }), and convert at the edges with toDate(timeZone) when you really need an instant.

With startName and endName the picker submits two hidden inputs in ISO format, so it works in a plain HTML form and with server actions:

Reading the range on the server
// The form posts checkIn=2026-11-12&checkOut=2026-11-14 (ISO 8601, no time zone).
export async function POST(request: Request) {
  const form = await request.formData();
  const checkIn = parseDate(String(form.get('checkIn')));   // from @reactloom/dates
  const checkOut = parseDate(String(form.get('checkOut')));
  if (checkOut.compare(checkIn) < 2) return Response.json({ error: 'Two nights minimum' }, { status: 422 });
  // …
}

Rules: limits, unavailable dates and errors

  • minValue and maxValue bound the calendar and mark typed dates outside them as invalid.
  • isDateUnavailable greys out individual dates (bookings, holidays, weekends with isWeekend(date, locale)).
  • Rules about the range itself, such as a minimum stay, belong in error: the message is shown under the field, linked to it and announced. Check the same rule on the server.