PeakUI

TimeField

Segmented field for typing a time

Usage

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

Anatomy

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

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

Examples

Variants

With Prefix and Suffix

With Description

Required

Disabled

Full Width

Invalid

Granularity

Hour Cycle

Controlled

With Validation

Customization

Tailwind CSS

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

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 TimeField component uses these CSS classes (view source styles and group styles):

Field Classes

  • .time-field - Column of label, group and messages
  • .time-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="time-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

TimeField

PropTypeDefaultDescription
fullWidthbooleanfalseMakes the field fill its container
valueTimeValue | null-The current time (controlled)
defaultValueTimeValue | null-The initial time (uncontrolled)
onChange(value: MappedTimeValue<T> | null) => void-Called when the time changes
minValueTimeValue | null-Earliest valid time
maxValueTimeValue | null-Latest valid time
placeholderValueTimeValue | null-Time the empty segments start from when stepped
granularity"hour" | "minute" | "second""minute"Smallest unit shown
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: TimeFieldRenderProps) => string)-Additional classes, or a function of the render props
...restEvery React Aria TimeField prop

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

TimeField.Input

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

TimeField.InputContainer

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

TimeField.Segment

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

TimeField.Prefix

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

TimeField.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 TimeField receives these values:

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

On this page