Markup
<div class="tray-anchor tray-anchor--block" data-tray="datepicker">
<button class="tray-select-trigger" type="button" data-placeholder>
…calendar icon… <span class="tray-select-trigger__value">Pick a day</span>
</button>
<div class="tray-pop tray-pop--roomy">
<div data-tray="calendar" data-min="2026-11-15"></div>
</div>
<input type="hidden" name="day">
</div>The trigger is the system's field; the panel is raised with the float shadow. A single date closes the panel as soon as it is picked. For a range, set data-mode="range" data-months="2" on the calendar: two months sit side by side, in the manner of travel booking pickers, and the trigger reads "18 – 24 Nov 2026".
Optional parts inside the panel:
tray-datepicker__presetswith buttons carryingdata-preset="7": the last seven days, ending today.tray-pop__footwith adata-clearbutton and adata-applybutton; with Apply present the panel stays open until it is pressed.
The hidden input holds YYYY-MM-DD or start/end.
Accessibility
The trigger is a <button> with aria-haspopup="dialog", aria-controls and an aria-expanded that follows the panel, and the panel is a role="dialog" named as the field is. Enter, Space or the down arrow opens the panel and moves focus to the picked day, or to today, where the Calendar's keys take over. Escape closes it, as does pressing Apply, or, without Apply, picking the date or the end of the range; each returns focus to the trigger. Name the trigger with a <label for>, aria-labelledby or aria-label: the behaviour adds the tray-select-trigger__value to its aria-labelledby, given an id, so the chosen date is heard with the field's name ("Report period, 26 Oct – 8 Nov 2026"). Under prefers-reduced-motion: reduce the panel only fades, in a tenth of a second.
Do and don't
- Do write the placeholder as an instruction: "Pick a day".
- Do offer presets when a few ranges cover most needs (reports).
- Don't open the picker on focus; open it on click, Enter or the down arrow.
- Don't use it for dates far from today; pair it with a typed field or use selects.