DatePicker
"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.
"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
"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
"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
"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
Controlled date.
Initial date when uncontrolled.
Called with the picked day.
Earliest selectable day.
Latest selectable day.
Extra rule for unavailable days.
BCP 47 locale for the calendar and the trigger text.
First day of the week, 0 = Sunday. Defaults to the locale's first day.
How the trigger shows the date. Defaults to { dateStyle: "medium" }.
Shown while empty. Defaults to "Pick a date".
Trigger size. Defaults to "md".
Error state; set automatically inside a <Field error>.
Stretch the trigger to the container width.
Form field name: submits the date as YYYY-MM-DD.
Close the popover once a day is picked. Defaults to true.
Accessible name of the popover. Defaults to "Choose date".
Labels passed to the Calendar's month buttons.
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.