Time Field

React Time Field components allow users to select a specific time value using a segment-based input. They are commonly used in booking forms, scheduling flows, reminders, and time-based filters where precise keyboard entry is preferred.

9
30
AM

Choose a start time for the meeting.

Installation

The Time Field relies on the react-aria-components and react-stately libraries.

Install the component using the Tailgrids CLI.

npx @tailgrids/cli add time-field

Anatomy

import {
  TimeField,
  TimeFieldInput,
  TimeFieldLabel,
  TimeFieldDescription,
  TimeFieldError
} from "@/components/tailgrids/core/time-field";

export const TimeFieldExample = () => (
  <TimeField label="Meeting time">
    <TimeFieldLabel />
    <TimeFieldInput />
    <TimeFieldDescription />
    <TimeFieldError />
  </TimeField>
);

Examples

Basic Usage

A standard time field implementation using segments for precise time entry.

––
––
AM

Choose a start time for the meeting.

Controlled

Manage the time value externally using the value and onChange props.

5
30
PM

Uncontrolled

An uncontrolled time field with a defaultValue prop.

9
30
AM

With Seconds

Enable second selection by setting the granularity prop to second.

9
30
15
AM

With Timezone

Display and manage time zones within the time field.

14
30

Validation

Display error messages and validation states when the time value is invalid.

––
––
AM

Business hours only

Must be between 9 AM and 5 PM

API Reference

TimeField

The segment-based time input component.

PropTypeDefaultDescription
valueTimeValue-The current value (controlled).
defaultValueTimeValue-The default value (uncontrolled).
onChange(value: TimeValue) => void-Handler that is called when the value changes.
labelstring-The content to display as the label.
descriptionstring-The content to display as the description.
errorMessagestring | ((v: ValidationResult) => string)-The content to display as the error message.
hourCycle12 | 24-Whether to use 12 or 24 hour cycle.
granularity'hour' | 'minute' | 'second''minute'The smallest unit of time to display.
hideTimeZonebooleanfalseWhether to hide the time zone abbreviation.
minValueTimeValue-The minimum allowed time.
maxValueTimeValue-The maximum allowed time.
disabledbooleanfalseWhether the input is disabled.
readOnlybooleanfalseWhether the input is read only.
requiredbooleanfalseWhether the input is required.
invalidbooleanfalseWhether the input is shown in invalid state.
classNamestring-Additional CSS classes to apply to the container.

TimeFieldLabel

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the label.

TimeFieldInput

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the input container.

TimeFieldDescription

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the description.

TimeFieldError

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the error message.

Accessibility

  • Keyboard Support: Users can navigate between time segments (hours, minutes, seconds, AM/PM) using Arrow keys and edit values using the number keys.
  • Screen Readers: Each segment is properly labeled and provides live updates to screen readers as values change.
  • Focus Management: Focus is managed automatically between segments for a seamless typing experience.