Skip to main content

Basic with presets

A button that looks like an input opens a calendar in a popup (aria-haspopup="dialog", so Esc, the click outside and the focus return come from the popup script). Click a start date, then an end date; the days in between are filled while the pointer moves. Presets fill the range in one click. The calendar is a role="grid" with a button in every cell whose name is the whole date (“Sunday, November 15, 2026”). Two hidden inputs, named with start-name and end-name, carry the start and end dates as YYYY-MM-DD in a form.

Released between

One month, no presets

The compact form: one month and no list of presets, for a narrow column or a form. On a small screen every picker shows one month.

Booking dates

Minimum and maximum

Days before min-date and after max-date (both YYYY-MM-DD) are disabled: they are crossed out, cannot be picked and are skipped by the keyboard. Here only 10 December 2026 up to 31 January 2027 can be chosen. A form usually sets the two dates on the server, for example from the current date.

Delivery window

Value and states

start-date and end-date set the chosen range, for example on an edit form. help and error work as on the input. required adds the * to the label and disabled turns the picker off; both are props because the value lives in hidden inputs, which the browser does not check.

Campaign dates

The campaign runs from the first day to the last day.

Leave dates

Choose the dates of your leave.

Locked period

Keyboard

Tab goes to the calendar with a single stop (the focused day); the keys then move inside it. Shift+Tab or Tab leaves it, and Esc closes the popup and returns to the button.

  • ← → a day
  • ↑ ↓ a week
  • Home End start or end of the week
  • Page Up Page Down a month (with Shift, a year)
  • Enter Space select
  • Esc close

Options reference

Alpine keeps the range and the months; Tailwind paints the states from data-range and data-today.

Part Value Description
x-data="dateRange({ … })" id, months, minDate, maxDate, presets id is optional (a date-range- id is generated without it) and must be unique on the page. months is 1 or 2 (2 only on wide screens). presets: false hides the list.
Trigger aria-haspopup="dialog", aria-controls Named by the label and by the value it shows.
Calendar role="grid" One per month, named by the month title; the day buttons carry the full date as their name.
Fields start-name, end-name Hidden inputs with YYYY-MM-DD, or empty. Without a name, that input is not sent with the form.
Presets Today, Last 7 days, Last 30 days, This month, Last month Edit PRESETS and preset() in the script.
Status role="status" Announces the range and the number of days when it changes.
Week starts on Monday Change the order of WEEKDAYS and the lead calculation for another start.