Skip to content

DatePicker

A day in one line of a form. Each part (day, month, year) is typed on its own, in the order the person’s language uses, or the day is picked from a calendar that opens.

import { DatePicker } from '@sypnia/ui/react'

On this page
  1. A day
  2. Between two days
  3. States
  4. When to use it
  5. For everyone
  6. Props

A day

Type the parts or open the calendar. The value under it is what a database receives.

Saved as 2026-12-01. After that day the key stops working.

Code
import { useState } from 'react';
import { DatePicker, Field, FormGrid } from '@sypnia/ui/react';

export default function Basic() {
  const [day, setDay] = useState<string | null>('2026-12-01');
  return (
    <FormGrid>
      <Field label="The key expires on" hint={day ? <>Saved as <code>{day}</code>. After that day the key stops working.</> : 'Without a date the key never expires.'}>
        <DatePicker value={day} onChange={setDay} />
      </Field>
    </FormGrid>
  );
}

Between two days

Only the last 30 days can be chosen, in the calendar and by typing.

Backups are kept for 30 days.

Code
import { DatePicker, Field, FormGrid } from '@sypnia/ui/react';

export default function Limits() {
  return (
    <FormGrid>
      <Field label="Restore the backup of" hint="Backups are kept for 30 days.">
        <DatePicker defaultValue="2026-11-16" min="2026-10-18" max="2026-11-17" />
      </Field>
    </FormGrid>
  );
}

States

Empty, with an error that says how to fix it, and disabled.

This day has passed. Choose a day after today.

Set when the project was created.

Code
import { DatePicker, Field, FormGrid } from '@sypnia/ui/react';

export default function States() {
  return (
    <FormGrid>
      <Field label="Start of the trial" optional>
        <DatePicker />
      </Field>
      <Field label="The key expires on" error="This day has passed. Choose a day after today.">
        <DatePicker defaultValue="2026-11-02" />
      </Field>
      <Field label="Created on" hint="Set when the project was created.">
        <DatePicker disabled defaultValue="2026-09-27" />
      </Field>
    </FormGrid>
  );
}

When to use it

Use it when

  • A date among other fields of a form: when a key expires, from which backup to restore.
  • The person may know the date by heart (they type it) or need to look at a calendar (they open it).

Do not use it when

  • It is a period: DateRangePicker.
  • It needs an hour too: DateTimePicker.
  • Only «last 7 days», «this month» and the like make sense: a Select with those periods is faster.

For everyone

  • Each part is a spinbutton: typing fills it and jumps to the next; up and down arrows change it; left and right move between parts; Backspace empties it.
  • The button opens the calendar in a dialog that keeps the focus inside; Escape closes it and returns the focus. Choosing a day closes it.
  • It never rejects the way a date was written: there is nothing to write wrong, because day, month and year are separate.
  • The value goes in and comes out as ISO text (2026-11-17), whatever the language shows.
  • Inside a Field it takes the label, the hint and the error by itself; alone, give it an aria-label.

Props

DatePickerTypeDefault
aria-describedby string
aria-label

The name for screen readers when there is no Field around it.

string
aria-labelledby string
className string
defaultValue string
disabled boolean
id

Inside a Field it comes from the Field.

string
invalid

Marks the value as wrong. Inside a `<Field error>` it is set for you.

boolean
max

The last day that can be chosen.

string
min

The first day that can be chosen, as `2026-11-01`.

string
name

The name of the value when it travels in a form.

string
onChange ((date: string | null) => void)
unavailable

Days that cannot be chosen: return true for them.

((date: string) => boolean)
value

The day, as `2026-11-17`, or null while it is empty.

string | null
  1. A day
  2. Between two days
  3. States
  4. When to use it
  5. For everyone
  6. Props

    Search pages, sections and terms