Date picker

Slant / Forms

A typed date in the reader’s locale, or one picked from a calendar.

Demo

Schedule

Usage

@tuttn/slant
import { DatePicker, Field } from '@tuttn/slant'

// In a Field, uncontrolled, submitted with a form as an ISO date ("2026-11-03").
<Field>
  <Field.Label>Due date</Field.Label>
  <DatePicker defaultValue={new Date(2026, 10, 3)} min={new Date()} name="due" />
</Field>

// Controlled: the value is a local-midnight Date, or null when the field is empty.
const [due, setDue] = useState<Date | null>(null)
<DatePicker value={due} onValueChange={setDue} label="Due date" />

// Another locale's order, weekdays only, and the calendar's open state controlled.
<DatePicker locale="en-GB" isDateDisabled={date => date.getDay() % 6 === 0}
  open={open} onOpenChange={setOpen} label="Release day" />

Props

PropTypeDefaultDescription
valueDate | null—The date, as a local midnight, or null when there is none. Pass it to control the field; leave it out to let the field keep its own.
defaultValueDate | nullnullThe date an uncontrolled field starts with.
onValueChange(value: Date | null) => void—Called with the new date (a local midnight), or null, when a pick in the calendar or a typed date commits a change. Typing alone doesn't call it.
localestringthe document's lang, else 'en'The locale dates are written and read in (its numeric order and separators), and the calendar's month and weekday names.
minDate—The earliest date that can be chosen. Typed dates before it are refused, and the calendar dims the days before it.
maxDate—The latest date that can be chosen. Typed dates after it are refused, and the calendar dims the days after it.
isDateDisabled(date: Date) => boolean—Called with a local midnight; dates it returns true for can't be chosen, typed or picked.
weekStartsOn0 | 10 where the locale's week starts on Sunday, else 1The calendar's first weekday: 1 for Monday, 0 for Sunday.
todayDatenowThe day the calendar marks as today, and the example date in the placeholder and the format hint.
openboolean—Whether the calendar is open. Pass it with onOpenChange to control it; leave it out and the field keeps its own state.
defaultOpenbooleanfalseWhether the calendar starts open, when uncontrolled.
onOpenChange(open: boolean) => void—Called with the new state whenever the calendar opens or closes.
labelstring—The accessible name of the input and the calendar, unless a Field's label or `aria-labelledby` names them.
namestring—Submits the date with a form: a hidden input holding an ISO date, `2026-11-03` (empty while there is none).
formstring—The id of the form the hidden input belongs to, when the field sits outside it.
size'sm' | 'md' | 'lg''md'Height on the control scale: 28, 34 or 40px at regular density.
invalidboolean—Sets aria-invalid and a danger border. Inside a Field, the field's `invalid` does this.
placementPlacement'bottom-end'Where the calendar opens against the field. Start and end follow the text direction; it flips to the other side when this one lacks room.
…restInputHTMLAttributes<HTMLInputElement>—The ref and every other attribute (id, placeholder, autoFocus, aria-*, handlers) reach the text input; className and style go on the group. `name` and `form` go on the hidden input that carries the ISO date.

Keyboard

  • In the input, Enter commits what was typed, and still submits a form around the field when it is a date; text that isn't one doesn't submit. Alt+ArrowDown opens the calendar.
  • Enter or Space on the calendar button opens the calendar, and closes it again.
  • In the calendar, the arrows move by day and week (Left and Right follow the reading direction), Page Up and Page Down by month, and Enter or Space picks the day. They stop at min and max, and reach days isDateDisabled rules out without picking them.
  • Escape closes the calendar without picking, and only the calendar when it sits in a Dialog. Tab past the last day (Shift+Tab before the month buttons) closes it and moves on as if it sat right after the button.

Typed dates

The field writes dates in the locale's numeric order and separators, on the Gregorian calendar: 11/03/2026 in en-US, 03/11/2026 in en-GB, 03.11.2026 in de. It reads them back the same way, with any separators between the three numbers, and also takes an ISO date (2026-11-03); a two-digit year is in the 2000s. What is typed is a draft until blur or Enter commits it. Empty text commits null. Text that isn't a date, or is a date outside min and max or ruled out by isDateDisabled, keeps the value, marks the input invalid until the text changes, and announces messages.invalidDate. The placeholder is today written in the format.

The calendar

The button opens a Calendar in a panel under the field, lined up with its end edge; it flips above when there is no room below. Focus goes to the chosen day, else today, else the nearest day that can be picked. A pick sets the value, writes it in the input, closes the calendar and returns focus to the button; a press outside or focus leaving closes it too. The panel renders in a portal that carries the root's theme and direction, and inside a Dialog it renders in the dialog, so it works there as anywhere.

Accessibility

The input is named by a Field's label, aria-labelledby or label, and described by the field's description, its error while invalid, and a format hint (messages.dateFormat, "Format: 11/03/2026"). It is a text input with a numeric keypad on phones. The button is named by messages.chooseDate and sets aria-haspopup="dialog", aria-expanded and, while open, aria-controls. The panel has the dialog role, named by the field's label (or label), else by messages.chooseDate. Read-only and disabled fields disable the button.

Forms

With a name, a hidden input submits the date as ISO, 2026-11-03, or an empty string while there is none; it is disabled with the field. The text input itself has no name. It is drawn as an Input group; for a time of day, see Time field.

Full source