Liking cljdoc? Tell your friends :D

x-calendar

A standalone, always-visible inline month calendar — a companion to x-date-picker. Where x-date-picker binds a calendar to a text input behind a popover, x-calendar renders the calendar grid directly in the page. Supports single-date and date-range selection, localized weekday and month names, configurable first-day-of-week, a month/year quick-jump header, and an optional ISO week-number column. Dates are ISO 8601 strings (YYYY-MM-DD).


Tag

<x-calendar></x-calendar>

Attributes

AttributeTypeDefaultDescription
modeenum"single"Selection mode: single or range
valuestringSelected date (YYYY-MM-DD), single mode
startstringRange start date (YYYY-MM-DD), range mode
endstringRange end date (YYYY-MM-DD), range mode
minstringEarliest selectable date (YYYY-MM-DD)
maxstringLatest selectable date (YYYY-MM-DD)
disabled-datesstringSpace/comma-separated list of individually disabled ISO dates
first-day-of-weekstring"0"First weekday column: 06 or a name (sundaysaturday)
localestringBCP 47 locale tag for weekday/month names (e.g. "en-US")
monthstringDisplayed month (YYYY-MM). Defaults to the value/start month, else today
show-week-numbersbooleanfalseShow an ISO week-number column down the left edge
disabledbooleanfalseDisables the whole calendar
range-allow-same-daybooleanfalseAllow start and end to be the same date in range mode
auto-swapbooleanfalseSwap start/end when the second pick precedes the first

Properties

PropertyTypeReflects attribute
modestringmode
valuestringvalue
startstringstart
endstringend
minstringmin
maxstringmax
monthstringmonth
localestringlocale
firstDayOfWeekstringfirst-day-of-week
disabledDatesstringdisabled-dates
disabledbooleandisabled
showWeekNumbersbooleanshow-week-numbers
rangeAllowSameDaybooleanrange-allow-same-day
autoSwapbooleanauto-swap

Events

EventCancelableDetailDescription
x-calendar-changeno{ value, start, end, mode }Fired after a date selection is committed
x-calendar-navigateno{ month }Fired when the displayed month changes

In single mode value carries the ISO date and start/end are empty. In range mode start/end carry the ISO dates (end empty until the range is complete) and value is empty. month is a YYYY-MM string.


Methods

MethodDescription
focus()Moves keyboard focus to the calendar grid
goToMonth(month)Jumps the displayed month to a YYYY-MM string
clear()Clears the current selection (value/start/end)

Slots

SlotDescription
(default)No default slot content expected

CSS custom properties

PropertyPurpose
--x-calendar-widthCalendar width (default 18rem)
--x-calendar-surfaceCalendar background
--x-calendar-bgQuick-jump panel background
--x-calendar-borderBorder colour
--x-calendar-radiusOuter corner radius
--x-calendar-textText colour
--x-calendar-mutedWeekday / week-number colour
--x-calendar-hoverDay / button hover background
--x-calendar-focusFocus-ring colour
--x-calendar-selected-bgSelected-day background
--x-calendar-selected-textSelected-day text
--x-calendar-range-bgRange-interior background
--x-calendar-range-textRange-interior text
--x-calendar-today-ringToday-marker ring colour

All consume shared x-theme tokens with fallbacks.


Accessibility

  • The grid has role="grid"; day cells are <button role="gridcell"> with aria-selected, aria-disabled, and a localized full-date aria-label.
  • Today's cell carries aria-current="date".
  • Roving tabindex: exactly one day cell is tab-reachable; arrow keys move it.
  • The month label has aria-live="polite" and aria-expanded for the quick-jump panel.
  • A disabled calendar sets aria-disabled="true" on the host.
  • Day-hover transitions respect prefers-reduced-motion.

Keyboard

KeyAction
ArrowLeftMove one day back
ArrowRightMove one day forward
ArrowUpMove one week back
ArrowDownMove one week forward
PageUpMove one month back
PageDownMove one month forward
HomeFirst day of the week
EndLast day of the week
Enter/SpaceSelect the focused date
EscapeClose the open quick-jump panel

Navigation is clamped to [min, max]; crossing a month boundary shifts the displayed month. The quick-jump panel is also dismissed by a pointer press outside the calendar or by selecting a day.


Examples

Single date

<x-calendar></x-calendar>

Date range

<x-calendar mode="range"></x-calendar>

Pre-selected value

<x-calendar value="2026-03-18"></x-calendar>

Bounded with disabled dates

<x-calendar
  min="2026-01-01"
  max="2026-12-31"
  disabled-dates="2026-03-17 2026-03-25">
</x-calendar>

Monday-first, localized, with week numbers

<x-calendar first-day-of-week="monday" locale="de-DE" show-week-numbers></x-calendar>

Listening to changes

document.querySelector('x-calendar').addEventListener('x-calendar-change', e => {
  console.log('selected:', e.detail.value || `${e.detail.start}…${e.detail.end}`);
});

ClojureScript (hiccup renderer)

[:x-calendar {:mode "range"
              :first-day-of-week "monday"
              :on-x-calendar-change
              (fn [e]
                (swap! state assoc
                       :start (.. e -detail -start)
                       :end   (.. e -detail -end)))}]

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close