PeakUI

DateRangePicker

Selects a date range from fields or a popover calendar

Usage

import {DateField, DateRangePicker, Label, RangeCalendar} from "@peakui/react";

Anatomy

import {
  DateField,
  DateRangePicker,
  Description,
  FieldError,
  Label,
  RangeCalendar,
} from "@peakui/react";

export default () => (
  <DateRangePicker>
    <Label />
    <DateField.Group>
      <DateField.Input slot="start">
        {(segment) => <DateField.Segment segment={segment} />}
      </DateField.Input>
      <DateRangePicker.RangeSeparator />
      <DateField.Input slot="end">
        {(segment) => <DateField.Segment segment={segment} />}
      </DateField.Input>
      <DateField.Suffix>
        <DateRangePicker.Trigger>
          <DateRangePicker.TriggerIndicator />
        </DateRangePicker.Trigger>
      </DateField.Suffix>
    </DateField.Group>
    <Description />
    <FieldError />
    <DateRangePicker.Popover>
      <RangeCalendar />
    </DateRangePicker.Popover>
  </DateRangePicker>
);

Examples

With Description

With Year Picker

Controlled

With Validation

minValue also limits the dates the calendar offers.

Custom Indicator

Disabled

Customization

Tailwind CSS

<DateRangePicker className="w-80">
  <DateRangePicker.Popover className="p-4">{/* RangeCalendar */}</DateRangePicker.Popover>
</DateRangePicker>

Global CSS

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

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

  .date-range-picker__range-separator {
    @apply px-2;
  }

  .date-range-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 DateRangePicker component uses these CSS classes (view source styles):

Base & Element Classes

  • .date-range-picker - Column of label, field and messages
  • .date-range-picker__trigger - The button that opens the popover
  • .date-range-picker__trigger-indicator - The icon inside the trigger
  • .date-range-picker__range-separator - The mark between the start and end inputs
  • .date-range-picker__popover - The popover container

Slots

  • [data-slot="date-range-picker"]
  • [data-slot="date-range-picker-trigger"]
  • [data-slot="date-range-picker-trigger-indicator"]
  • [data-slot="date-range-picker-range-separator"]
  • [data-slot="date-range-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

DateRangePicker

PropTypeDefaultDescription
valueRangeValue<DateValue> | null-Current value (controlled)
defaultValueRangeValue<DateValue> | null-Default value (uncontrolled)
onChange(value: RangeValue<MappedDateValue<T>> | null) => void-Handler called when the range 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
allowsNonContiguousRangesboolean-Whether a range may span unavailable dates
granularity"day" | "hour" | "minute" | "second"-Smallest unit the fields show
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
startNamestring-Name of the hidden start input, used when submitting an HTML form
endNamestring-Name of the hidden end input, used when submitting an HTML form
classNamestring | (values: DateRangePickerRenderProps) => string-Additional classes, or a function of the render props
childrenReactNode | (values: DateRangePickerRenderProps & {defaultChildren: ReactNode | undefined}) => ReactNode-Picker content, or a function of the render props
...restEvery React Aria DateRangePicker attribute is accepted, including aria-label

DateRangePicker.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

DateRangePicker.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

DateRangePicker.RangeSeparator

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

DateRangePicker.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 RangeCalendar
...restEvery React Aria Popover attribute is accepted

Render Props

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

PropTypeDescription
stateDateRangePickerStateThe 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