# Date Picker

> Part of Tray UI 0.2.0, a design system in plain HTML and CSS (MIT licence). Every page: https://trayui.com/llms.txt

A date picker is a field that opens a calendar and shows the chosen date in words.

## Markup
```html
<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__presets` with buttons carrying `data-preset="7"`: the last seven days, ending today.
- `tray-pop__foot` with a `data-clear` button and a `data-apply` button; 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.
