Skip to content

DatePicker

A date field with its own calendar, built from scratch.

import { DatePicker } from '@/design-system';

Examples

Nothing chosen.

'use client';

import { useState } from 'react';
import { DatePicker, Field } from '@/design-system';

export default function DatePickerBasic() {
  const [date, setDate] = useState('');

  return (
    <div className="grid gap-4 sm:grid-cols-2">
      <Field label="Date" hint={date ? `Value: ${date}` : 'Nothing chosen.'}>
        <DatePicker value={date} onChange={setDate} />
      </Field>
      <Field label="Within a range">
        <DatePicker
          defaultValue="2027-03-15"
          min="2027-03-10"
          max="2027-04-20"
        />
      </Field>
    </div>
  );
}

How it works

  • Values are YYYY-MM-DD strings. Dates are shown in US English, with weeks starting on Sunday. A date cannot be typed.
  • In the calendar, arrows move by a day or a week, Home and End to the ends of the week, and Page Up and Page Down by a month (with Shift, a year). Enter chooses and Escape closes.
  • The popup opens below when it fits, otherwise on the side with more room. It stays inside the window, scrolls when too tall, and follows the control while the page scrolls or resizes.
  • It is drawn above everything, including inside a Dialog, and keeps the theme around it. It uses the browser’s popover support.
  • With a name, a hidden input sends the value with a form. It has no required prop, so check the value yourself.

Props

DatePicker takes only these props.

DatePicker props
PropTypeDefaultDescription
valuestring—The chosen date, when you keep the state.
defaultValuestring''The starting date.
onChange(value: string) => void—Called with the chosen date.
minstring—The first date that can be chosen.
maxstring—The last date that can be chosen.
namestring—Sends the value with a form.
placeholderstring'Choose a date'Shown while no date is chosen.
disabledbooleanfalseStops it being used.
idstringfrom FieldThe id of the control.
aria-labelstring—A name, when it is used without a Field.
classNamestring—Extra classes, for spacing or width.

Tokens

Tokens
TokenDefaultSets
--field-radius--radius-controlCorner radius of the closed control
--field-background--surfaceFill
--field-border--borderBorder colour
--field-font-size0.875remText size
--popup-radius--radius-controlCorner radius of the popup
--popup-background--surfacePopup fill
--popup-border--borderPopup border
--popup-shadowa soft shadowPopup shadow
--day-radius--radius-controlCorner radius of a day