Calendar
A lightweight date / range picker. Markup and CSS are yours. The package fills
the grid and handles selection. <cinq-calendar> follows the
WAI-ARIA Authoring Practices date picker grid.
Inspired by @19h47/calendar.
When not to use it
Section titled “When not to use it”For one date with no day to rule out, <input type="date"> already does the
job without a script: the platform’s own picker, typing, min / max
validation and a YYYY-MM-DD value. Add autocomplete="bday" for a birth
date. Reach for <cinq-calendar> for a range or several dates in one field,
unavailable days, or a grid that has to follow the design. To keep the native
field and still offer the grid, open the calendar in a dialog.
Install
Section titled “Install”pnpm add @agencecinq/calendarImport once:
import "@agencecinq/calendar";Then write the grid markup. The host <cinq-calendar> fills weekday headers and
day cells, and wires selection + keyboard navigation. The snippets below call
the calendar el and take EVENTS from @agencecinq/utils.
HTML is the source of truth. The component does not invent missing ARIA attributes. Provide
role="grid", labels, and live regions yourself, andaria-multiselectable="true"on the grid inrangeandmultiplemodes.
<cinq-calendar id="calendar" lang="fr" deselectable> <header> <button type="button" commandfor="calendar" command="--previous-month" aria-label="Mois précédent">Précédent</button> <h2 id="calendar-title" aria-live="polite"></h2> <button type="button" commandfor="calendar" command="--next-month" aria-label="Mois suivant">Suivant</button> </header> <table role="grid" aria-labelledby="calendar-title"> <thead> <tr></tr> </thead> <tbody></tbody> </table></cinq-calendar>No class to add: see Required markup for what the calendar looks for, and Commands for the month buttons.
The component upgrades automatically on connectedCallback.
Examples
Section titled “Examples”Interactive demos below cover single date, range, multiple dates, preselection,
a form, a dialog, bounds, language / week start, and an events calendar
decorated on calendar:render.
Single date
Locale fr and deselectable. Click the selected day again to clear. Try the keyboard once a day is focused: arrows, Home/End, Page Up/Page Down.
Selection : Aucune date
Date range
mode="range". Pick a start day, then an end day. Hover (or move focus) paints the in-between preview. A third click resets the range. The hint under the grid follows :state(empty), :state(picking) and :state(pending): a pretend server check holds the end for 0.8 s.
Choisissez la date de début.
Choisissez la date de fin.
Vérification des disponibilités…
Selection : Aucune date
Multiple dates
mode="multiple". Toggle discrete days in and out of the selection. No range painting. Click a selected day again to remove it. Capped at 3 days here by canceling calendar:before-change.
Selection : Aucune date
Preselected dates
Seed the view with data-month, data-year, and data-picked. Here a range covering mid-November 2025.
Selection : 2025-11-10 to 2025-11-18
Form
<cinq-calendar> is a form field: name="stay", mode="range" and required. Submit with a missing end to get the browser's own message. Reset brings back the initial selection.
FormData : -
In a dialog
A native <input type="date"> stays the field. The button opens the calendar in a <dialog> with command="show-modal", without a script. A picked day fills the input and closes the dialog. Escape closes it too, and focus goes back to the button.
Bounds
The page script sets min to today and max 60 days later. Days outside are aria-disabled and cannot be selected (still in the keyboard grid).
Selection : Aucune date
Language & week start
The select sets lang on the calendar, an observed attribute: labels follow through Intl, the week starts on the language's first day unless first-day says otherwise, and the language's weekend from Intl.Locale#getWeekInfo() is grayed: Friday alone for fa, Friday and Saturday for ar. It also sets dir from getTextInfo(): ar and fa read from the right, and the arrow keys follow.
firstDay = 1(0=Sun ... 6=Sat)
Selection : Aucune date
Advanced: event markers
Decorate the days on calendar:render: wrap each one in <time>, mark weekends, and paint dots on days that have events. Only event days are selectable. Others get aria-disabled.
Selection : Aucune date
Single date
Section titled “Single date”Default mode="single". Add deselectable to clear by clicking the selected day again.
<cinq-calendar lang="fr" deselectable name="arrival"> <!-- header + table --></cinq-calendar>Date range
Section titled “Date range”Set mode="range". First click is the start, second is the end. Hover or
keyboard focus previews the range. A third click resets.
<cinq-calendar lang="fr" mode="range" name="stay"> <!-- header + table --></cinq-calendar>While the range waits for its end, the calendar matches :state(picking). The
Date range demo above shows a hint with it: see
Custom states.
Multiple dates
Section titled “Multiple dates”Set mode="multiple". Each click toggles a day in or out of the selection. No
range preview.
<cinq-calendar lang="fr" mode="multiple" name="availability"> <!-- header + table --></cinq-calendar>The package does not enforce a maximum number of days. Cancel the change that would go over yours:
import { EVENTS } from "@agencecinq/utils";
const MAX = 3;
el.addEventListener(EVENTS.CALENDAR_BEFORE_CHANGE, event => { if (event.detail.values.length > MAX) event.preventDefault();});Preselected dates
Section titled “Preselected dates”Seed the viewed month and selection from attributes:
<cinq-calendar lang="fr" mode="range" data-month="10" data-year="2025" data-picked='["2025-11-10","2025-11-18"]'> <!-- header + table --></cinq-calendar><cinq-calendar> is a form-associated custom element. Inside a <form>, its
name is submitted with the picked days joined by commas (2026-11-10,
2026-11-10,2026-11-14). Validation follows a date field, with the browser’s
own messages: required needs at least one day (both ends in range), and a
day before min or after max blocks the submission. form.reset() brings
back the data-picked selection, and disabled (or a disabled <fieldset>)
leaves the field out. A range with only its start is invalid, like a half-typed
date. The element has the validation API of a native field: validity,
validationMessage, checkValidity() and reportValidity().
<form> <p id="stay-label">Dates du séjour</p> <cinq-calendar id="stay" name="stay" mode="range" required> <header> <!-- commandfor="stay" buttons --> <h2 id="stay-title" aria-live="polite"></h2> </header> <table role="grid" aria-labelledby="stay-label stay-title" aria-multiselectable="true"> <thead> <tr></tr> </thead> <tbody></tbody> </table> </cinq-calendar> <button>Réserver</button></form>Name the grid with aria-labelledby: a <label for> on the host does not
reach it.
In a dialog
Section titled “In a dialog”Keep a native <input type="date"> as the field and open the calendar in a
<dialog> to fill it. command and commandfor open and close the dialog
without a script, the browser closes it on Escape and gives focus back to the
button. The calendar has no name, so only the input is submitted. The
In a dialog demo above runs this code.
<label for="arrival">Arrivée</label><input type="date" id="arrival" name="arrival" min="2026-10-16" required /><button type="button" command="show-modal" commandfor="arrival-dialog"> Choisir dans le calendrier</button>
<dialog id="arrival-dialog" aria-labelledby="arrival-dialog-title"> <h2 id="arrival-dialog-title">Date d'arrivée</h2> <cinq-calendar id="arrival-calendar" lang="fr" min="2026-10-16"> <header> <button type="button" commandfor="arrival-calendar" command="--previous-month" aria-label="Mois précédent">‹</button> <h3 id="arrival-month" aria-live="polite"></h3> <button type="button" commandfor="arrival-calendar" command="--next-month" aria-label="Mois suivant">›</button> </header> <table role="grid" aria-labelledby="arrival-dialog-title arrival-month"> <thead> <tr></tr> </thead> <tbody></tbody> </table> </cinq-calendar> <button type="button" command="close" commandfor="arrival-dialog">Fermer</button></dialog>On open, show the input’s date and focus it (today when the input is empty). A picked day fills the input and closes the dialog:
import { dateFromDay } from "@agencecinq/calendar";import { EVENTS } from "@agencecinq/utils";
const input = document.getElementById("arrival");const dialog = document.getElementById("arrival-dialog");const calendar = dialog.querySelector("cinq-calendar");
dialog.addEventListener("toggle", ({ newState }) => { if (newState !== "open") return;
const date = input.value ? dateFromDay(input.value) : new Date();
calendar.current = { month: date.getMonth(), year: date.getFullYear(), day: input.value || null, }; calendar.setPicked(input.value ? [input.value] : [], false); calendar.render({ focus: true });});
calendar.addEventListener(EVENTS.CALENDAR_CHANGE, ({ detail }) => { input.value = detail.values[0] ?? ""; input.dispatchEvent(new Event("change", { bubbles: true })); dialog.close();});
// Confirming the day already picked changes nothing, so no calendar:change.calendar.addEventListener("click", ({ target }) => { if (target.closest("[data-day]")?.dataset.day === input.value) dialog.close();});Bounds
Section titled “Bounds”min and max (YYYY-MM-DD) work as on <input type="date">: days outside
stay in the grid with aria-disabled="true" and cannot be picked, and a picked
day that a moving bound leaves outside makes the field invalid. Without them,
every day can be picked. Both are observed, so a departure calendar can
follow the arrival:
import { dayFromDate } from "@agencecinq/calendar";import { EVENTS } from "@agencecinq/utils";
const [arrival, departure] = document.querySelectorAll("cinq-calendar");const today = dayFromDate(new Date());
arrival.setAttribute("min", today);departure.setAttribute("min", today);
arrival.addEventListener(EVENTS.CALENDAR_CHANGE, ({ detail }) => { departure.setAttribute("min", detail.values[0] ?? today);});Unavailable days
Section titled “Unavailable days”Set aria-disabled="true" on a day button on calendar:render. Clicks, the
keyboard and the range preview already skip it. The Advanced: event
markers demo does this for days without events.
const unavailable = ["2026-11-11", "2026-11-12"];
el.addEventListener(EVENTS.CALENDAR_RENDER, () => { el.querySelectorAll("[data-day]").forEach(button => { if (unavailable.includes(button.dataset.day)) { button.setAttribute("aria-disabled", "true"); } });});el.render();A range can still go over an unavailable day. Refuse it:
el.addEventListener(EVENTS.CALENDAR_BEFORE_CHANGE, event => { const [start, end] = event.detail.values;
if (end && unavailable.some(day => day > start && day < end)) { event.preventDefault(); }});Language & week start
Section titled “Language & week start”The labels follow lang through Intl: the calendar’s own lang, or the
closest ancestor’s (<html lang>), else the browser’s language. The same
attribute tells screen readers which language to read them in. The week starts
on the language’s first day, first-day (0=Sun … 6=Sat) overrides it.
Both are observed on the calendar itself: after changing an ancestor’s lang,
call render(). Use the select in the playground to try en,
fr, de, es, ja, ar, fa and th.
Labels stay on the Gregorian calendar the grid is built on, even for a language
with another calendar of its own: fa shows نوامبر ۲۰۲۶, not the Persian
month, and th shows 2026, not the Buddhist year. Day numbers use the
language’s digits, Persian ones for fa. Add -u-nu-latn to lang
(fa-u-nu-latn) to keep Latin digits everywhere.
<!-- French, week starts Monday --><cinq-calendar lang="fr">...</cinq-calendar>
<!-- English labels, force Monday --><cinq-calendar lang="en" first-day="1">...</cinq-calendar>Right-to-left languages (ar, fa, he) also need dir="rtl", usually
next to lang on <html>. The table then lays the week out from the right,
and the left and right arrow keys follow what is on screen. Characters such as ‹ ›
mirror themselves in right-to-left text: mirror only icons that do not, such
as an SVG, with [command] svg:dir(rtl) { scale: -1 1; }. Round range ends
with logical corners such as border-start-start-radius.
Change the language at runtime:
const el = document.querySelector("cinq-calendar");
el.lang = "ja";
// right to leftel.lang = "ar";el.dir = new Intl.Locale(el.lang).getTextInfo().direction;Decorate days
Section titled “Decorate days”calendar:render bubbles from the host after each render: on connection, on
each month change, and when an observed attribute changes. The cells already
carry their state, so decorate the day buttons from there. Keep their
data-day. The playground Advanced: event markers example adds <time>,
weekend styling and event dots this way, and disables days without events.
el.addEventListener(EVENTS.CALENDAR_RENDER, ({ detail }) => { // detail.year and detail.month (`0`-`11`): the month on screen el.querySelectorAll("[data-day]").forEach(button => { button.innerHTML = `<time datetime="${button.dataset.day}">${button.textContent.trim()}</time>`; });});el.render();The first render happens on connection, often before your script runs. Call
render() once after adding the listener, or listen on document from a
script that runs first.
Required markup
Section titled “Required markup”The calendar finds its parts in your HTML, no class needed.
| Element | Required | Role |
|---|---|---|
<cinq-calendar> |
Yes | Host. Needs an id only for the month buttons |
<tbody> of the role="grid" table |
Yes | Filled with the day cells |
<thead> <tr> of the same table |
No | Filled with the weekday headers |
[aria-live] |
No | The first one in the calendar gets the month and year as its whole text, announced on each change: put it on the title itself |
Buttons with commandfor |
No | Month navigation, see Commands |
Each generated day button carries data-day="YYYY-MM-DD".
Commands
Section titled “Commands”Buttons move the calendar with
invoker commands:
commandfor names the calendar id, command the move. The browser sends the
command on click, Enter or Space, and the button can sit anywhere in the page.
command |
Moves |
|---|---|
--previous-month / --next-month |
One month back / forward |
--previous-year / --next-year |
One year back / forward |
The calendar needs an id for these buttons, and only for them: commandfor
points to it. Without month buttons, leave the id out: Page Up and Page Down
still change the month from the grid. From a script,
button.commandForElement = calendar links a button without any id.
Selection state
Section titled “Selection state”The calendar writes the state as attributes, no class:
- On each
<td>:aria-selected="true"for a selected day, every day of a range included. Inmode="range",data-rangeinside the range (ends included),data-startanddata-endon its ends. These three also paint the range to come while the pointer or the focus chooses its end. - On each day button: the full date as
aria-label(lundi 16 novembre 2026),aria-current="date"on today, andaria-disabled="true"on days that cannot be picked. - On the calendar itself: custom states rather than attributes, see Custom states.
These rules weigh the same, so the last one that matches wins:
/* picked day */td[aria-selected="true"] [data-day] { background: #111827; color: #fff;}
/* inside a range, ends included */td[data-range] [data-day] { background: #e5e7eb; color: #111827;}
/* range ends */td[data-start] [data-day],td[data-end] [data-day] { background: #111827; color: #fff;}Custom states
Section titled “Custom states”The calendar itself matches custom states:
| State | When |
|---|---|
:state(empty) |
No day is picked |
:state(picking) |
A range has its start and waits for its end |
:state(pending) |
A waitUntil() of calendar:before-change holds a change |
A state only changes the look, so say it in words too: put the hints in a
role="status" element and hide the hints, not the element. The status stays
in the page, so screen readers announce a hint when it shows. Prefer
role="status" to aria-live here: the calendar writes the month in the first
[aria-live] it finds. The Date range demo shows the three hints, with a
pretend server check on the end.
<cinq-calendar lang="fr" mode="range" name="stay"> <!-- header + table --> <div role="status"> <p data-hint="empty">Choisissez la date d'arrivée.</p> <p data-hint="picking">Choisissez la date de départ.</p> <p data-hint="pending">Vérification des disponibilités…</p> </div></cinq-calendar>/* each hint shows with its state, and the check alone while it runs */cinq-calendar:not(:state(empty)) [data-hint="empty"],cinq-calendar:not(:state(picking)) [data-hint="picking"],cinq-calendar:not(:state(pending)) [data-hint="pending"],cinq-calendar:state(pending) [data-hint]:not([data-hint="pending"]) { display: none;}
cinq-calendar:state(pending) [data-day] { cursor: progress;}Attributes
Section titled “Attributes”| Attribute | Description |
|---|---|
lang |
Language of the labels and of their reading, own or inherited (BCP 47). Observed |
mode |
single (default), range, or multiple |
deselectable |
Allow clearing selection in mode="single" |
min / max |
First / last day that can be picked (YYYY-MM-DD). Observed |
name |
Form field name, also in the event details |
required |
Needs at least one day, both ends in range, to submit. Observed |
disabled |
Leaves the field out of the form and disables every day |
first-day |
Week start (0=Sun … 6=Sat). Defaults from the language. Observed |
button-class |
Extra classes on day buttons |
data-month / data-year |
Initial view (month is 0-11) |
data-picked |
JSON array of preselected YYYY-MM-DD days, in order (start then end in a range) |
Events
Section titled “Events”Dispatched on the host <cinq-calendar>.
| Event | Constant | Detail |
|---|---|---|
calendar:render |
CALENDAR_RENDER |
{ year: number, month: number } |
calendar:before-change |
CALENDAR_BEFORE_CHANGE |
{ values: string[], name?: string, waitUntil } |
calendar:change |
CALENDAR_CHANGE |
{ values: string[], name?: string } |
calendar:render bubbles after each render, once the cells carry their state
(see Decorate days).
calendar:before-change comes first when a click or a key would change the
selection, with the selection to come in values. It does not bubble.
preventDefault() cancels the change, and event.detail.waitUntil(promise)
holds it until the promise settles (a rejection cancels it). Meanwhile, the
calendar matches :state(pending).
calendar:change bubbles once the selection has changed. setPicked() skips
calendar:before-change, and dispatches calendar:change unless emit is
false.
import { EVENTS } from "@agencecinq/utils";
document.querySelector("cinq-calendar")?.addEventListener( EVENTS.CALENDAR_CHANGE, ({ detail }) => console.log(detail.values, detail.name),);Keyboard
Section titled “Keyboard”| Key | Action |
|---|---|
| Arrow keys | Move by day / week. Left and right follow the screen, mirrored under dir="rtl" |
| Home / End | First / last day of the week |
| Page Up / Page Down | Previous / next month |
| Shift + Page Up / Down | Previous / next year |
| Enter / Space | Select the focused day |
| Method / property | Description |
|---|---|
options |
Resolved options. locale and firstDay are read from lang and first-day on each render: set the attributes instead |
picked |
Selected days as YYYY-MM-DD |
current |
Viewed { month, year, day } |
render() |
Rebuild the grid |
setPicked(picked, emit?) |
Assign the selection (days in order, start then end in a range), mirror data-picked and paint the grid. Emits calendar:change unless emit is false |
move(delta) |
Navigate by months (-1 = previous, 1 = next) |
destroy() |
Detach listeners, clear the grid, its validity and its states |
validity, validationMessage |
As on a native field |
checkValidity(), reportValidity() |
As on a native field |
Exported helpers: getFirstDay, dayFromDate, dateFromDay.
Migration from 3.x
Section titled “Migration from 3.x”Version 4.0 reads its markup, language and bounds from standard HTML: no more
.js-* classes, lang instead of locale, invoker commands for the month
buttons, state attributes instead of classes, and a form-associated element
validated by required, min and max. renderInner() gives way to
calendar:render. Step by step changes in the
README.