Date Pickers
The calendar is vanilla-calendar-pro
Version 3.4.0 of Vanilla Calendar Pro (MIT licence), loaded only by a page that has a date picker.
<div class="field max-w-xs">
<label for="demo-date-picker">Expiration Date</label>
<div class="date-picker">
<input class="input" type="text" id="demo-date-picker" placeholder="YYYY-MM-DD" />
<div data-popover aria-hidden="true"></div>
</div>
</div>
A page loads the calendar library itself, before the Tsugi script
The library is not in the bundle. A page with a date picker loads dist/js/vanilla-calendar-pro.min.js before the Tsugi script.
<script src="js/vanilla-calendar-pro.min.js" defer></script>
<script src="tsugi.min.js" defer></script>
The markup is a text input and an empty panel
Focus or a click on the field opens the calendar. A date can also be typed as YYYY-MM-DD.
<div class="date-picker">
<input class="input" type="text" placeholder="YYYY-MM-DD" />
<div data-popover aria-hidden="true"></div>
</div>
The field's value attribute is the starting date
<div class="field max-w-xs">
<label for="demo-date-picker-value">Created From</label>
<div class="date-picker">
<input class="input" type="text" id="demo-date-picker-value" value="2026-05-29" placeholder="YYYY-MM-DD" />
<div data-popover aria-hidden="true"></div>
</div>
</div>
data-format="long" shows a written date, chosen from the calendar only
<div class="field max-w-xs">
<label for="demo-date-picker-long">Expiration Date</label>
<div class="date-picker" data-format="long">
<input class="input" type="text" id="demo-date-picker-long" value="2026-05-29" placeholder="Select a date" />
<div data-popover aria-hidden="true"></div>
</div>
</div>
data-mode="range" picks a start and an end date
<div class="field max-w-sm">
<label for="demo-date-picker-range">Date Range</label>
<div class="date-picker" data-mode="range">
<input class="input" type="text" id="demo-date-picker-range" value="2026-08-27 to 2026-09-25" placeholder="YYYY-MM-DD to YYYY-MM-DD" />
<div data-popover aria-hidden="true"></div>
</div>
</div>
data-time="24" picks a time as well as the date
<div class="field max-w-sm">
<label for="demo-date-picker-time">Publish At</label>
<div class="date-picker" data-time="24">
<input class="input" type="text" id="demo-date-picker-time" value="2026-05-29 14:30" placeholder="YYYY-MM-DD HH:MM" />
<div data-popover aria-hidden="true"></div>
</div>
</div>
data-time="12" shows AM and PM; the hidden input keeps a 24-hour time
A button in place of the field shows the dates
The control can be a button holding a span. The span shows the chosen dates, a range with an arrow between its two ends, or the root's data-placeholder while there are none. The hidden input carries the starting value. A date cannot be typed.
A button shows the date, or data-placeholder while none is chosen
Presets are ready-made dates beside the calendar
The page writes a data-presets group of buttons in the panel. A preset's value is the dates it chooses, written by the server, so the script works out no dates itself. Choosing one closes the panel, and the calendar stays for dates of one's own. From 768px wide the presets are a column after the calendar; below that they are two columns under it.
One control for a period: presets, or dates from the calendar. data-format="medium" writes the dates with a short month
<div class="date-picker" data-mode="range" data-format="medium">
<button type="button" class="btn" data-variant="outline" aria-expanded="false"><span>Sep 7, 2026 → Oct 6, 2026</span><i class="icon icon-chevron-down" aria-hidden="true"></i></button>
<div data-popover aria-hidden="true">
<div data-presets role="group" aria-label="Period">
<button type="button" value="2026-10-06 to 2026-10-06" aria-pressed="false">Today</button>
<button type="button" value="2026-09-30 to 2026-10-06" aria-pressed="false">Last 7 Days</button>
<button type="button" value="2026-09-07 to 2026-10-06" aria-pressed="true">Last 30 Days</button>
<button type="button" value="2026-07-09 to 2026-10-06" aria-pressed="false">Last 90 Days</button>
</div>
</div>
<input type="hidden" name="period" value="2026-09-07 to 2026-10-06" />
</div>
data-min and data-max limit the dates that can be chosen
Between October 5 and November 15, 2026.
<div class="field max-w-xs">
<label for="demo-date-picker-limits">Delivery Date</label>
<div class="date-picker" data-min="2026-10-05" data-max="2026-11-15">
<input class="input" type="text" id="demo-date-picker-limits" placeholder="YYYY-MM-DD" aria-describedby="demo-date-picker-limits-help" />
<div data-popover aria-hidden="true"></div>
</div>
<p id="demo-date-picker-limits-help">Between October 5 and November 15, 2026.</p>
</div>
The input's data-size sets the height; a width utility on the root sets the width
<div class="flex flex-wrap items-start gap-4">
<div class="date-picker w-36">
<input class="input" data-size="sm" type="text" placeholder="YYYY-MM-DD" aria-label="Small date" />
<div data-popover aria-hidden="true"></div>
</div>
<div class="date-picker w-40">
<input class="input" type="text" placeholder="YYYY-MM-DD" aria-label="Default date" />
<div data-popover aria-hidden="true"></div>
</div>
<div class="date-picker w-44">
<input class="input" data-size="lg" type="text" placeholder="YYYY-MM-DD" aria-label="Large date" />
<div data-popover aria-hidden="true"></div>
</div>
</div>
A hidden input carries the value for the form, always as YYYY-MM-DD
Inside a dialog the calendar opens above the dialog, and Escape closes the calendar first
<button type="button" class="btn" data-variant="outline" data-dialog-open="demo-date-picker-dialog">Change Expiration</button>
<dialog id="demo-date-picker-dialog" class="dialog" aria-labelledby="demo-date-picker-dialog-title">
<div>
<header>
<h2 id="demo-date-picker-dialog-title">Change Expiration Date</h2>
</header>
<section>
<div class="field">
<label for="demo-date-picker-dialog-field">Expiration Date</label>
<div class="date-picker">
<input class="input" type="text" id="demo-date-picker-dialog-field" placeholder="YYYY-MM-DD" />
<div data-popover aria-hidden="true"></div>
</div>
</div>
</section>
<footer>
<button type="button" class="btn" data-variant="outline" data-dialog-close>Cancel</button>
<button type="button" class="btn" data-dialog-close>Save</button>
</footer>
<button type="button" class="btn" data-variant="ghost" data-size="icon-sm" aria-label="Close dialog" data-dialog-close><i class="icon icon-x" aria-hidden="true"></i></button>
</div>
</dialog>
Invalid, and disabled
Enter a date as YYYY-MM-DD.
<div class="grid max-w-xl gap-4 sm:grid-cols-2">
<div class="field" data-invalid>
<label for="demo-date-picker-invalid">Start Date</label>
<div class="date-picker">
<input class="input" type="text" id="demo-date-picker-invalid" value="2026-02-30" placeholder="YYYY-MM-DD" aria-invalid="true" aria-describedby="demo-date-picker-invalid-error" />
<div data-popover aria-hidden="true"></div>
</div>
<p id="demo-date-picker-invalid-error" role="alert">Enter a date as YYYY-MM-DD.</p>
</div>
<div class="field">
<label for="demo-date-picker-disabled">End Date</label>
<div class="date-picker">
<input class="input" type="text" id="demo-date-picker-disabled" value="2026-03-15" placeholder="YYYY-MM-DD" disabled />
<div data-popover aria-hidden="true"></div>
</div>
</div>
</div>
The page reads the dates from the change event, and sets them through value
No dates yet.
<div class="flex max-w-sm flex-col gap-3">
<div class="date-picker" id="demo-date-picker-events" data-mode="range">
<input class="input" type="text" placeholder="YYYY-MM-DD to YYYY-MM-DD" aria-label="Date range" />
<div data-popover aria-hidden="true"></div>
</div>
<div class="flex flex-wrap gap-2">
<button type="button" class="btn" data-variant="outline" data-size="sm" onclick="document.getElementById('demo-date-picker-events').value = '2026-10-01 to 2026-10-31'">Set October</button>
<button type="button" class="btn" data-variant="outline" data-size="sm" onclick="document.getElementById('demo-date-picker-events').value = ''">Clear</button>
<button type="button" class="btn" data-variant="outline" data-size="sm" onclick="event.stopPropagation(); document.getElementById('demo-date-picker-events').open()">Open</button>
</div>
<p class="text-muted-foreground text-sm" id="demo-date-picker-events-result">No dates yet.</p>
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
const picker = document.getElementById("demo-date-picker-events");
const result = document.getElementById("demo-date-picker-events-result");
picker.addEventListener("change", (event) => {
result.textContent = event.detail.value === "" ? "Cleared." : "Chosen: " + event.detail.dates.join(" and ");
});
});
</script>
Other library options go through mount()
Pass any option of the library when starting the date picker by hand.
window.tsugi.mount('date-picker', document.getElementById('delivery-date'), {
firstWeekday: 1,
disableWeekdays: [0, 6],
});
API Reference
Attributes
| Attribute | On | Values | Default | Description |
|---|---|---|---|---|
| data-mode | .date-picker | "range" | none | A start and an end date, chosen with two clicks. Two months show side by side from 768px wide, one below that. Without it, one date. |
| data-format | .date-picker | "long", "medium" | none | The control shows a written date and takes none typed: "May 29, 2026" for long, "Sep 7, 2026" for medium. Without it the control shows YYYY-MM-DD, and a field takes it typed. |
| data-time | .date-picker | "24", "12" | none | A time as well as the date, on a 24-hour clock or with AM and PM. The value is "YYYY-MM-DD HH:MM" on a 24-hour clock. A day click leaves the calendar open for the time. Not with data-mode="range". |
| data-min | .date-picker | YYYY-MM-DD | none | The first date that can be chosen. |
| data-max | .date-picker | YYYY-MM-DD | none | The last date that can be chosen. |
| value | the text input, or the hidden input | YYYY-MM-DD, or YYYY-MM-DD HH:MM | empty | The starting date: 2026-05-29 for a date, 2026-05-01 to 2026-05-29 for a range, 2026-05-29 14:30 with data-time. The hidden input's value wins when there is one. A date picker with a button starts from the hidden input. |
| data-placeholder | .date-picker | text | none | With a button: the text the button shows while no date is chosen. With dates it shows them, a range as "start → end". |
| data-presets | a div in the panel | none | none | Holds the presets: one button for each ready-made date or range, shown beside the calendar. |
| value | a preset's button | YYYY-MM-DD | none | The dates the preset chooses, written as the starting value is: one date, or "start to end" for a range. |
| aria-pressed | a preset's button | "true", "false" | none | "true" on the preset whose value is the chosen dates. The page writes it for the starting value; the script keeps it up to date. |
| data-size | the text input | "sm", "lg" | none | The height of the field. |
Methods and properties
| Member | Type | Description |
|---|---|---|
| value | property | Read: the chosen date, or "start to end" for a range, as YYYY-MM-DD; an empty string for none. Set: takes the same text; an empty string clears it. |
| open() | method | Opens the calendar. |
| close() | method | Closes it. |
| calendar | property, read only | The library's Calendar object, for anything its own API offers. |
Events
| Event | On | Detail | Description |
|---|---|---|---|
| change | .date-picker | { value, dates } | Sent when the dates or the time change, by a click, by a preset, by typing or by setting value. A time slider sends it once it is let go. value is the text; dates is a list of one or two. |
Keyboard
| Key | Description |
|---|---|
| Tab | From the field or the button into the calendar, through its controls and then the presets, then out, which closes it. |
| Arrow keys | Move between the days. |
| Enter or Space | Chooses the day. On the button, opens or closes the calendar. On a preset, chooses its dates. |
| Escape | Closes the calendar and returns to the field or the button. A dialog around it stays open. |
Once the script has started it, the element carries data-date-picker-initialized="true" and sends tsugi:initialized. The methods and properties above are on the element itself.