Officina UI
Components

DatePicker

Field that opens a calendar popover to pick a single date or a date range.

DatePicker is a field that opens a calendar popover (built on react-day-picker) for choosing a date. It is controlled, and the mode prop switches behavior: in the default 'single' mode value is a Date | undefined and onChange returns the selected date; in 'range' mode value is a DateRange ({ from, to }). Add a label and placeholder for the field.

Example

Preview
import { DatePicker } from '@officina/ui';
import { useState } from 'react';

function DueDate() {
  const [date, setDate] = useState<Date | undefined>();
  return <DatePicker label="Due date" value={date} onChange={setDate} placeholder="Pick a date" />;
}

API

PropTypeDefaultDescription
onChange*((date: Date | undefined) => void) | ((range: DateRange | undefined) => void)—Called with the newly selected date. Called with the newly selected range.
value*Date | DateRange | undefined—Selected date, or `undefined` when empty (controlled). Selected start/end range, or `undefined` when empty (controlled).
disabledboolean—
invalidboolean—Marks the field invalid for validation styling and `aria-invalid`.
labelstring—Field label shown above the input.
modeenum—Single-date selection mode (default). Date-range selection mode.
namestring—Form field name, for native form submission / form libraries.
placeholderstring—Placeholder text when no date is selected. Placeholder text when no range is selected.

On this page