# Date field

Picks a day or a month from a calendar.

This is the HTML to build it with `dex.css`, for work outside the Dex codebase. Read https://brand.meetdex.ai/design.md first: it says how to set up a page and how to use the stylesheet. The page at https://brand.meetdex.ai/components/date-field shows the Dex app's own React component, which only works inside the Dex codebase.

## HTML

A button that looks like a field opens a calendar in a popover. Open and close it with the script in https://brand.meetdex.ai/components/combobox.md.

```html
<label class="dex-field-label" id="start-label" for="start">Start date</label>
<div class="dex-popover-anchor">
  <button type="button" id="start" class="dex-field dex-field-button" aria-labelledby="start-label" aria-haspopup="dialog" aria-expanded="false">
    <svg aria-hidden="true"><!-- Lucide calendar --></svg>
    <span>18 March 2026</span>
  </button>
  <div class="dex-popover dex-popover--calendar" role="dialog" aria-labelledby="start-label" hidden>
    <div class="dex-calendar">
      <div class="dex-calendar-head">
        <button class="dex-calendar-nav" aria-label="Previous month"><svg aria-hidden="true"><!-- Lucide chevron-left --></svg></button>
        <button class="dex-calendar-caption" aria-label="Choose a month">March 2026</button>
        <button class="dex-calendar-nav" aria-label="Next month"><svg aria-hidden="true"><!-- Lucide chevron-right --></svg></button>
      </div>
      <div class="dex-calendar-grid">
        <span class="dex-calendar-weekday">Mo</span><!-- Tu We Th Fr Sa Su -->
        <button class="dex-calendar-day dex-calendar-day--outside" tabindex="-1">23</button><!-- … 28 Feb -->
        <button class="dex-calendar-day">1</button><!-- … -->
        <button class="dex-calendar-day" aria-current="date">12</button>
        <button class="dex-calendar-day" aria-pressed="true">18</button>
        <!-- … to the end of the last week -->
      </div>
    </div>
  </div>
</div>
```

- **The grid**: seven weekdays from Monday, then whole weeks. Days of the months either side take `dex-calendar-day--outside`.
- **Today** takes `aria-current="date"` (a 50% edge). **The chosen day** takes `aria-pressed="true"` (a primary fill).
- **Month precision**: for CV history, the popover holds a `dex-calendar-grid dex-calendar-grid--months` of twelve `dex-calendar-day` buttons ("Jan" to "Dec") under a caption with the year. The day grid's caption opens the same grid.
- **Earliest and latest**: `disabled` on the days outside them, and on an arrow that would leave them.
- **No value yet**: `<span class="dex-muted">Choose a date</span>` in the button.
- **Ongoing**: the end date of a role someone still holds is a `disabled` button reading "Present", with no value.
- **Invalid**: `aria-invalid="true"` on the button and a `dex-field-error` under it: "Choose a date after your start date."
- **Read-only**: `aria-readonly="true"`, a muted fill and helper text saying where the date came from.

## States

- The field takes the 75% edge while its calendar is open.
- Days take a muted fill on hover. Focus is the 75% edge inside the day; on the chosen day, a 1px line in its text colour.

## Rules

- Day precision for a date someone knows exactly, such as a start date or an interview. Month precision for CV history, where nobody remembers the day.
- Show the date written out in the field: "18 March 2026", "March 2026".
- Bound a pair of dates by each other, so a role can never end before it starts.
- For a role that's still going, show "Present" on the end date instead of asking for a future date.
- On a phone the Dex app opens the calendar in a bottom sheet. `dex.css` has no bottom sheet; in a mock, keep the popover.
