Skip to content

Date and time

DateTimePicker

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

export function PublishAt() {
  return (
    <Field label="Publish at">
      <DateTimePicker name="publishAt" locale="en-GB" hourCycle={24} fullWidth />
    </Field>
  );
}

Picks a day and a time in one popover: a Calendar beside a column of time slots, then Cancel or Apply. It reuses the DatePicker trigger. Use DatePicker or TimePicker when you only need one of the two.

onChange runs only on Apply. With name, a hidden input submits "YYYY-MM-DDTHH:mm" in local time.

If you import per-component CSS from @cherry-design-system/react/css/* instead of styles.css, DateTimePicker needs date-picker.css, calendar.css, time-picker.css and button.css besides its own stylesheet.

Examples

Controlled

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

export function Meeting() {
  const [when, setWhen] = useState<Date | null>(null);
  return (
    <Field label="Meeting" hint={when ? when.toISOString() : "Not scheduled"}>
      <DateTimePicker value={when} onChange={setWhen} step={15} hourCycle={12} />
    </Field>
  );
}

Limits and disabled days

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

const now = new Date();

export function Delivery() {
  return (
    <Field label="Delivery window" required>
      <DateTimePicker
        min={now}
        isDateDisabled={(d) => d.getDay() === 0}
        dateFormatOptions={{ weekday: "short", day: "numeric", month: "short" }}
        placeholder="Choose a delivery slot"
      />
    </Field>
  );
}

Translated labels

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

export function Cita() {
  return (
    <Field label="Cita">
      <DateTimePicker
        locale="es-ES"
        weekStartsOn={1}
        labels={{ dialog: "Elegir fecha y hora", time: "Hora", cancel: "Cancelar", apply: "Aplicar" }}
        calendarLabels={{ previousMonth: "Mes anterior", nextMonth: "Mes siguiente" }}
      />
    </Field>
  );
}

Properties

valueDate | null

Controlled date and time.

defaultValueDate | null

Initial value when uncontrolled. Defaults to null.

onChange(value: Date) => void

Called on Apply with the picked day at the picked time.

minDate

Earliest selectable day.

maxDate

Latest selectable day.

isDateDisabled(date: Date) => boolean

Extra rule for unavailable days.

stepnumber

Minutes between time slots. Defaults to 30.

hourCycle12 | 24

12 or 24-hour clock for the slots.

localestring

BCP 47 locale for the calendar, the slots and the trigger text.

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

First day of the week, 0 = Sunday.

dateFormatOptionsIntl.DateTimeFormatOptions

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

placeholderReactNode

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

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 "YYYY-MM-DDTHH:mm" (local time).

labels{ dialog?: string; time?: string; cancel?: string; apply?: string }

Accessible names and button text (DateTimePickerLabels). Default to "Choose date and time", "Time", "Cancel" and "Apply".

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-time-picker with states data-open, data-invalid and data-disabled. Parts: cherry-date-time-picker__popover, __body, __time, __time-label, __footer. The trigger uses the DatePicker classes (cherry-date-picker__trigger and so on), the grid uses the Calendar classes and the slots use the TimePicker option classes.

Reads --cherry-border-default for the divider, --cherry-fg-muted for the time label and --cherry-primary-default with --cherry-primary-fg for the selected slot.

Accessibility

A dialog with the Calendar grid and a time listbox; Cancel and Apply are buttons. Escape closes the dialog and returns focus to the trigger. Label it with Field.