Skip to content
nexubDesign System
v11.9.0

Components · Web Components

Date Picker Element

AlphaAdded v11.6.0

`<nx-date-picker>`: a typed date field and a calendar as a form-associated web component, for server-rendered pages without React. The value is `YYYY-MM-DD`.

<script type="module" src="https://cdn.jsdelivr.net/npm/@nexub/elements/dist/define.js"></script>

Install: npm install @nexub/elements. No build step: the script tag above registers <nx-date-picker>. With a bundler, import '@nexub/elements/define'; once does the same.

View as Markdown

Usage

Use it for
  • A date, month or year on a page with no React: server-rendered HTML, a plain `<form method="post">`.

  • Where `<input type="date">` would do, but the calendar must match Nexub in every browser and the value must never shift across time zones.

Use something else for
  • In a React app: use DatePicker from `@nexub/react`.

  • A range (from and to): use DateRangePicker in React, or two fields.

  • A date and a time: use DateTimePicker in React.

Playground

Props

Value: 2026-03-14

TSX
<nx-date-picker ref={ref} id="start" max="2026-12-31" min="2026-01-01" name="start" value="2026-03-14" />

Examples

Default

Type a date or open the calendar. Rendered here in React 19; on a server-rendered page it is the same tag.

Value: 2026-03-14

Months, in a form

`granularity="month"` posts `YYYY-MM`; `required` and `min` block the submit until the value is valid.

Posted: nothing yet

States

  • Value: 2026-03-14

    default
  • Value: 2026-03-14

    disabled
  • Value: 2026-03-14

    invalid
  • Value: 2026-03-14

    size="sm"
  • Value: 2026-03-14

    size="md"
  • Value: 2026-03-14

    size="lg"

Props

Props
PropTypeDefaultDescription
namestring—The form field name: a <form> posts the value under it.
valuestring—The starting value: YYYY-MM-DD, YYYY-MM or YYYY by granularity; what form.reset() goes back to. The value property is the current value. In React, server rendering writes value as this attribute; in a client-only render pass defaultValue.
granularity'day' | 'month' | 'year'—day (default), month or year: the calendar shows days, months or years, and the value has that precision.
minstring—Earliest value, same format. Earlier cells are disabled; a typed earlier date is invalid (rangeUnderflow).
maxstring—Latest value (rangeOverflow).
requiredboolean—Empty is invalid (valueMissing).
disabledboolean—Not editable, not posted; the calendar button is disabled.
readonlyboolean—Posted but not editable; the calendar doesn’t open.
localestring—BCP 47 locale for month and weekday names, the week start and the typed format. Defaults to the nearest lang.
size'sm' | 'md' | 'lg'—sm, md (default) or lg: the control heights of @nexub/react.
aria-labelstring—Names the field when it has no <label for>.
change eventEvent—When the value changes: a day picked, or a typed date committed on blur or Enter.
show() / close()() => void—Open the calendar (focused on the selected date, or today) and close it; open is true while it is.
invalidboolean—Shows the field as invalid (aria-invalid, the error border) whatever its validity, as @nexub/react's invalid.

Accessibility

ARIA roles

textbox (the typed field) and a button with `aria-haspopup="dialog"` and `aria-expanded`dialog (modal), named "Pick a date", "Pick a month" or "Pick a year"grid with gridcell buttons for days (`aria-selected`, `aria-current="date"` on today); a group of toggle buttons (`aria-pressed`) for months and years

Keyboard

  • Enter (in the field)

    Commits the typed date and submits the form.

  • Arrow keys

    Move a day (a week up or down); in the month and year grids, one cell (three up or down). Mirrored in RTL.

  • PageUp / PageDown

    Previous or next month; with Shift, year. In the month and year grids, the previous or next page.

  • Home / End

    Start or end of the week (the row).

  • Enter / Space

    Picks the focused cell and closes the calendar.

  • Escape

    Closes the calendar without picking.

Focus

  • Opening moves focus to the selected date (or today, kept inside `min` and `max`); the grid is one tab stop.

  • Closing, by picking, Escape or a click outside, returns focus to the field.

  • Below 48rem the calendar is a bottom sheet.

Screen reader

  • The field is named from the host’s `<label for>` (or a wrapping `<label>`, or `aria-label`), copied into the shadow root.

  • The month or year heading is a polite live region, so paging is announced.

  • `aria-required` and `aria-invalid` follow the field; a typed date that can’t be read stays as typed and is invalid, with a message that shows the expected format.

Notes

  • The value is a plain string, never a `Date`, so it never moves a day across time zones.

  • Shadow DOM: page CSS can’t break the inside. Style it with the theme variables, or `::part(field)`, `::part(input)`, `::part(button)` and `::part(calendar)`.

  • Motion only under `prefers-reduced-motion: no-preference`; forced colours redraw it with system colours.

On iOS & Android