Components · Web Components
Date Picker Element
`<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.
Usage
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.
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
<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.
Months, in a form
`granularity="month"` posts `YYYY-MM`; `required` and `min` block the submit until the value is valid.
States
Value: 2026-03-14
defaultValue: 2026-03-14
disabledValue: 2026-03-14
invalidValue: 2026-03-14
size="sm"Value: 2026-03-14
size="md"Value: 2026-03-14
size="lg"
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| name | string | — | The form field name: a <form> posts the value under it. |
| value | string | — | 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. |
| min | string | — | Earliest value, same format. Earlier cells are disabled; a typed earlier date is invalid (rangeUnderflow). |
| max | string | — | Latest value (rangeOverflow). |
| required | boolean | — | Empty is invalid (valueMissing). |
| disabled | boolean | — | Not editable, not posted; the calendar button is disabled. |
| readonly | boolean | — | Posted but not editable; the calendar doesn’t open. |
| locale | string | — | 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-label | string | — | Names the field when it has no <label for>. |
| change event | Event | — | 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. |
| invalid | boolean | — | Shows the field as invalid (aria-invalid, the error border) whatever its validity, as @nexub/react's invalid. |
Accessibility
ARIA roles
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
@nexub/react-native, DateTimeField (the platform picker).