Skip to content

Date and time

DatePicker

tsx
"use client";
import { useState } from "react";
import { DatePicker, Field } from "@cherry-design-system/react";

export function DueDate() {
  const [due, setDue] = useState<Date | null>(null);
  return (
    <Field label="Due date">
      <DatePicker locale="en-US" value={due} onChange={setDue} fullWidth />
    </Field>
  );
}

An input-like trigger that opens a Calendar in a native popover. Use it for a date field in a form. Use DateTimePicker when a time is needed too.

Examples

In a form

name adds a hidden input that submits the date as YYYY-MM-DD.

tsx
"use client";
import { DatePicker, Field } from "@cherry-design-system/react";

export function Birthday() {
  return (
    <form action="/profile" method="post">
      <Field label="Birthday" required>
        <DatePicker name="birthday" max={new Date()} />
      </Field>
    </form>
  );
}

Format and placeholder

tsx
"use client";
import { DatePicker, Field } from "@cherry-design-system/react";

export function Launch() {
  return (
    <Field label="Launch day" hint="Weekdays only.">
      <DatePicker
        locale="en-GB"
        weekStartsOn={1}
        formatOptions={{ weekday: "long", day: "numeric", month: "long" }}
        placeholder="Choose a weekday"
        isDateDisabled={(d) => d.getDay() === 0 || d.getDay() === 6}
      />
    </Field>
  );
}

Keep open after selecting

tsx
"use client";
import { DatePicker, Field } from "@cherry-design-system/react";

export function Reminder() {
  return (
    <Field label="Reminder">
      <DatePicker size="sm" closeOnSelect={false} dialogLabel="Choose reminder date" />
    </Field>
  );
}

Error

tsx
"use client";
import { DatePicker, Field } from "@cherry-design-system/react";

export function Start() {
  return (
    <Field label="Start date" error="Pick a start date.">
      <DatePicker />
    </Field>
  );
}

Properties

valueDate | null

Controlled date.

defaultValueDate | null

Initial date when uncontrolled.

onChange(date: Date) => void

Called with the picked day.

minDate

Earliest selectable day.

maxDate

Latest selectable day.

isDateDisabled(date: Date) => boolean

Extra rule for unavailable days.

localestring

BCP 47 locale for the calendar and the trigger text.

weekStartsOn0 | 1 | 2 | 3 | 4 | 5 | 6

First day of the week, 0 = Sunday. Defaults to the locale's first day.

formatOptionsIntl.DateTimeFormatOptions

How the trigger shows the date. Defaults to { dateStyle: "medium" }.

placeholderReactNode

Shown while empty. Defaults to "Pick a date".

size"sm" | "md" | "lg"

Trigger size. Defaults to "md".

invalidboolean

Error state; set automatically inside a <Field error>.

fullWidthboolean

Stretch the trigger to the container width.

namestring

Form field name: submits the date as YYYY-MM-DD.

closeOnSelectboolean

Close the popover once a day is picked. Defaults to true.

dialogLabelstring

Accessible name of the popover. Defaults to "Choose date".

calendarLabels{ previousMonth?: string; nextMonth?: string }

Labels passed to the Calendar's month buttons.

wrapperClassNamestring

Class for the outer wrapper (className goes to the trigger button).

The ref and native <button> attributes (except value, defaultValue, onChange and children) go to the trigger button.

Styling

Root class cherry-date-picker with data-size (sm, md, lg) and states data-open, data-invalid, data-disabled, data-full-width. Parts: cherry-date-picker__trigger, __icon, __value, __placeholder, __popover. The popover contains a Calendar, so it also needs the Calendar styles (included in styles.css).

Reads the field tokens for the trigger and --cherry-bg-elevated, --cherry-elevation-lg and --cherry-radius-xl for the popover.

Accessibility

The trigger opens a dialog and focus moves into the Calendar grid; Escape closes it and returns focus to the trigger. Label it with Field.