Skip to content

Calendar

Allows users to view and select dates within a monthly or yearly context. The component provides navigation between months and years.

Usage

Use the calendar when users need to choose specific dates, such as scheduling events. For filtering data by date, use a Date Picker. Make sure it is paired with clear labels and context to prevent confusion, especially when selecting critical dates.

Keyboard Handling

The user can use the following keyboard shortcuts in order to navigate trough the calendar:

  • Up / Down — Moves focus to the day above/below the current day.
  • Right — Moves focus to the next day.
  • Left — Moves focus to the previous day.
  • Enter / Space — Selects the focused day.
  • Home — Selects the first day of the month.
  • End — Selects the last day of the month.
  • PageUp — Selects the same or closest day of the previous month.
  • PageDown — Selects the same or closest day of the next month.

API Reference

Component attubute(s)

x-h-calendar

Attributes

AttributeValuesRequiredDescription
data-aria-prev-yearstringfalseSets the aria-label attribute value for the previous year button.
data-aria-prev-monthstringfalseSets the aria-label attribute value for the previous month button.
data-aria-next-monthstringfalseSets the aria-label attribute value for the next month button.
data-aria-next-yearstringfalseSets the aria-label attribute value for the next year button.
data-alignbottom-start
bottom
bottom-end
right-start
right
right-end
left-start
left
left-end
top-start
top
top-end
falseAligns the calendar popover relative to the trigger.

Events

EventDescription
changeTriggered when the value or model has changed. The date is passed in the event.detail object under the date key.

Config

You can pass a configuration object to the calendar as an expression or as a value.

Example:

html
<div x-h-calendar="calConfig"></div>
<script>
  Alpine.data('controller', () => ({
    calConfig: { locale: 'en-US', firstDay: 1, min: '2025-01-10', max: '2025-12-20' },
  }));
</script>
KeyDescription
localeThe locale of the calendar as a BCP 47 language tag. If not provided, it's automatically set from the user preferences.
firstDayThe start day of the week. 0 is Sunday.
minThe earliest date selectable. Must be provided in the standard ISO 8601 format - YYYY-MM-DD.
maxThe latest date selectable. Must be provided in the standard ISO 8601 format - YYYY-MM-DD.
modelAsIsoThe value saved in the model will be an ISO 8601 datetime string, regardless of locale and the format displayed in the input.
optionsIntl.DateTimeFormat options.

Examples

html
<div x-data>
  <div x-h-calendar @change="console.log('Selected:', $event.detail.date)"></div>
</div>
html
<div x-data="{ caldate: new Date().toISOString() }">
  <div x-h-calendar="{ locale: 'en-US', firstDay: 1 }" x-model="caldate"></div>
</div>