PeakUI

DateField

Segmented field for typing a date

Usage

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

Anatomy

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

export default () => (
  <DateField>
    <Label />
    <DateField.Group>
      <DateField.Prefix />
      <DateField.InputContainer>
        <DateField.Input>{(segment) => <DateField.Segment segment={segment} />}</DateField.Input>
      </DateField.InputContainer>
      <DateField.Suffix />
    </DateField.Group>
    <Description />
    <FieldError />
  </DateField>
);

Examples

Variants

With Prefix and Suffix

With Description

Required

Disabled

Full Width

Invalid

Granularity

Controlled

With Validation

Customization

Tailwind CSS

<DateField className="w-64">
  <Label>Date</Label>
  <DateField.Group className="rounded-full">
    <DateField.Input>{(segment) => <DateField.Segment segment={segment} />}</DateField.Input>
  </DateField.Group>
</DateField>

Global CSS

@layer components {
  .date-input-group {
    --date-input-group-radius: var(--radius-lg);
  }

  .date-input-group__segment {
    @apply font-mono;
  }
}

Styling Reference

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

CSS Classes

The DateField component uses these CSS classes (view source styles and group styles):

Field Classes

  • .date-field - Column of label, group and messages
  • .date-field--full-width - Fills the container width

Group Classes

  • .date-input-group - Shell with fill, border and focus ring
  • .date-input-group__input - Borderless, transparent segmented input
  • .date-input-group__input-container - Horizontal scroll area around the input
  • .date-input-group__segment - One editable part of the date
  • .date-input-group__prefix - Slot before the input
  • .date-input-group__suffix - Slot after the input

Variant Classes

  • .date-input-group--primary - Field fill with shadow (default)
  • .date-input-group--secondary - Neutral fill without shadow

Modifier Classes

  • .date-input-group--full-width - Fills the container width

Slots

  • [data-slot="date-field"]
  • [data-slot="date-input-group"]
  • [data-slot="date-input-group-input"]
  • [data-slot="date-input-group-input-container"]
  • [data-slot="date-input-group-segment"]
  • [data-slot="date-input-group-prefix"]
  • [data-slot="date-input-group-suffix"]

CSS Variables

VariablePurpose
--date-input-group-bgFill
--date-input-group-bg-hoverFill on hover
--date-input-group-bg-focusFill on focus
--date-input-group-fgText colour
--date-input-group-placeholderPlaceholder and slot colour
--date-input-group-borderBorder colour
--date-input-group-border-hoverBorder colour on hover
--date-input-group-border-focusBorder colour on focus
--date-input-group-radiusCorner radius
--date-input-group-shadowField shadow

Interactive States

  • Hover: :hover or [data-hovered] on .date-input-group
  • Focus: :focus-within or [data-focus-within] on .date-input-group; :focus or [data-focused] on .date-input-group__segment
  • Placeholder: [data-placeholder] on .date-input-group__segment
  • Invalid: [data-invalid] or [aria-invalid="true"] on .date-input-group, [data-invalid] on the segment, and the field hides its description
  • Disabled: [data-disabled] or [aria-disabled="true"] on .date-input-group

API Reference

DateField

PropTypeDefaultDescription
fullWidthbooleanfalseMakes the field fill its container
valueDateValue | null-The current date (controlled)
defaultValueDateValue | null-The initial date (uncontrolled)
onChange(value: MappedDateValue<T> | null) => void-Called when the date changes
minValueDateValue | null-Earliest valid date
maxValueDateValue | null-Latest valid date
isDateUnavailable(date: DateValue) => boolean-Marks a date invalid
placeholderValueDateValue | null-Date the empty segments start from when stepped
granularity"day" | "hour" | "minute" | "second"-Smallest unit shown; "day" for dates, "minute" for times
hourCycle12 | 24-Clock used for hours; follows the locale by default
hideTimeZonebooleanfalseHides the time zone of a zoned value
shouldForceLeadingZerosboolean-Pads every segment to its full width
isDisabledbooleanfalseDisables the field
isReadOnlybooleanfalseKeeps the value but blocks editing
isRequiredbooleanfalseRequires a value; sets data-required
isInvalidboolean-Marks the field invalid
namestring-Name of the hidden input submitted with a form
classNamestring | ((values: DateFieldRenderProps) => string)-Additional classes, or a function of the render props
...restEvery React Aria DateField prop

DateField.Group

PropTypeDefaultDescription
variant"primary" | "secondary""primary"Visual style of the group
fullWidthbooleanfalseMakes the group fill its container
classNamestring | ((values: GroupRenderProps) => string)-Additional classes, or a function of the render props
...restEvery React Aria Group prop

DateField.Input

PropTypeDefaultDescription
children(segment: DateSegment) => ReactElement-Renders one segment; pass it to DateField.Segment
classNamestring | ((values: DateInputRenderProps) => string)-Additional classes, or a function of the render props
...restEvery React Aria DateInput prop

DateField.InputContainer

PropTypeDefaultDescription
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to "div"
classNamestring-Additional classes
...restEvery attribute of the rendered element

DateField.Segment

PropTypeDefaultDescription
segmentDateSegment-The segment passed by DateField.Input
classNamestring-Additional classes
...restEvery React Aria DateSegment prop

DateField.Prefix

PropTypeDefaultDescription
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to "div"
classNamestring-Additional classes
...restEvery attribute of the rendered element

DateField.Suffix

PropTypeDefaultDescription
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to "div"
classNamestring-Additional classes
...restEvery attribute of the rendered element

Render Props

className on DateField receives these values:

PropTypeDescription
isInvalidbooleanWhether the field is invalid
isDisabledbooleanWhether the field is disabled
isReadOnlybooleanWhether the field is read only

On this page