PeakUI

DatePicker

Selects a date from a field or a popover calendar

Usage

import {Calendar, DateField, DatePicker, Label} from "@peakui/react";

Anatomy

import {Calendar, DateField, DatePicker, Description, FieldError, Label} from "@peakui/react";

export default () => (
  <DatePicker>
    <Label />
    <DateField.Group>
      <DateField.Input>{(segment) => <DateField.Segment segment={segment} />}</DateField.Input>
      <DateField.Suffix>
        <DatePicker.Trigger>
          <DatePicker.TriggerIndicator />
        </DatePicker.Trigger>
      </DateField.Suffix>
    </DateField.Group>
    <Description />
    <FieldError />
    <DatePicker.Popover>
      <Calendar />
    </DatePicker.Popover>
  </DatePicker>
);

Examples

With Description

With Year Picker

Controlled

With Validation

minValue also limits the dates the calendar offers.

Granularity

Custom Indicator

Disabled

Customization

Tailwind CSS

<DatePicker className="w-72">
  <DatePicker.Popover className="p-4">{/* Calendar */}</DatePicker.Popover>
</DatePicker>

Global CSS

@layer components {
  .date-picker {
    @apply flex flex-col gap-2;
  }

  .date-picker__trigger {
    @apply rounded-lg text-accent;
  }

  .date-picker__popover {
    @apply rounded-lg border border-border p-4;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The DatePicker component uses these CSS classes (view source styles):

Base & Element Classes

  • .date-picker - Column of label, field and messages
  • .date-picker__trigger - The button that opens the popover
  • .date-picker__trigger-indicator - The icon inside the trigger
  • .date-picker__popover - The popover container

Slots

  • [data-slot="date-picker"]
  • [data-slot="date-picker-trigger"]
  • [data-slot="date-picker-trigger-indicator"]
  • [data-slot="date-picker-popover"]

Interactive States

The component supports both CSS pseudo-classes and data attributes:

  • Focus: :focus-visible or [data-focus-visible] on trigger
  • Disabled: :disabled, [data-disabled] or [aria-disabled="true"] on trigger
  • Invalid: [data-invalid] or [aria-invalid="true"] on picker
  • Entering: [data-entering] on popover
  • Exiting: [data-exiting] on popover

API Reference

DatePicker

PropTypeDefaultDescription
valueDateValue | null-Current value (controlled)
defaultValueDateValue | null-Default value (uncontrolled)
onChange(value: MappedDateValue<T> | null) => void-Handler called when the value changes
minValueDateValue | null-Minimum selectable date, also applied to the calendar
maxValueDateValue | null-Maximum selectable date, also applied to the calendar
isDateUnavailable(date: DateValue) => boolean-Whether a date is unavailable in the field
granularity"day" | "hour" | "minute" | "second"-Smallest unit the field shows
isOpenboolean-Open state of the popover (controlled)
defaultOpenboolean-Default open state of the popover (uncontrolled)
onOpenChange(isOpen: boolean) => void-Handler called when the popover opens or closes
isDisabledboolean-Whether the picker is disabled
isReadOnlyboolean-Whether the value can be selected but not changed
isRequiredboolean-Whether user input is required
isInvalidboolean-Whether the value is invalid
namestring-Name of the hidden input, used when submitting an HTML form
classNamestring | (values: DatePickerRenderProps) => string-Additional classes, or a function of the render props
childrenReactNode | (values: DatePickerRenderProps & {defaultChildren: ReactNode | undefined}) => ReactNode-Picker content, or a function of the render props
...restEvery React Aria DatePicker attribute is accepted, including aria-label

DatePicker.Trigger

PropTypeDefaultDescription
classNamestring | (values: ButtonRenderProps) => string-Additional classes, or a function of the render props
childrenReactNode | (values: ButtonRenderProps & {defaultChildren: ReactNode | undefined}) => ReactNode-Trigger content, or a function of the render props
...restEvery React Aria Button attribute is accepted

DatePicker.TriggerIndicator

PropTypeDefaultDescription
classNamestring-Additional classes
childrenReactNodecalendar iconCustom indicator content
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'span'
...restEvery <span> attribute is accepted

DatePicker.Popover

PropTypeDefaultDescription
placement"bottom" | "bottom left" | "bottom right" | "bottom start" | "bottom end" | "top" | "top left" | "top right" | "top start" | "top end" | "left" | "left top" | "left bottom" | "start" | "start top" | "start bottom" | "right" | "right top" | "right bottom" | "end" | "end top" | "end bottom""bottom"Placement of the popover relative to the field
classNamestring | (values: PopoverRenderProps & {defaultClassName: string | undefined}) => string-Additional classes, or a function of the render props
childrenReactNode-Popover content, usually a Calendar
...restEvery React Aria Popover attribute is accepted

Render Props

DatePicker accepts function children and className, and receives these values:

PropTypeDescription
stateDatePickerStateThe state of the picker
isFocusWithinbooleanWhether focus is inside the picker
isFocusVisiblebooleanWhether keyboard focus is visible inside the picker
isDisabledbooleanWhether the picker is disabled
isInvalidbooleanWhether the value is invalid
isOpenbooleanWhether the popover is open
isReadOnlybooleanWhether the picker is read-only
isRequiredbooleanWhether the picker is required

On this page