oakoss/ui
Components

Time Field

A time input with hour, minute and day-period segments that follow the locale.

SourceReact Aria
Start timeYour local time.

Installation

npx shadcn@latest add @oakoss/time-field

Usage

import { parseTime } from '@internationalized/date';

import { TimeField } from '#/components/ui/inputs/time-field';

<TimeField defaultValue={parseTime('09:30')} label="Start time" />;

The value is a Time from Internationalized Date: parseTime reads 09:30, and value.toString() writes 09:30:00. A time with a date is a Date Field with granularity="minute".

Examples

Hour cycle and seconds

The locale decides between a 12-hour clock with a day-period segment and a 24-hour one; hourCycle forces either. granularity="second" adds a seconds segment.

Departure
Lap time

Accessibility

React Aria handles the same segments and keys as Date Field: a group named by the label, a spinbutton per unit, and arrow keys to move between and step them. In a 12-hour locale, typing the first letter of the day period sets it.

Known React Aria issue: after clearing the field, the hidden form input keeps the old value (react-spectrum#9801).

API

TimeField

Extends React Aria's TimeField.

Props

Takes the same layout props as Date Field (label, description, errorMessage, errors, size, start and end), and all React Aria TimeField props. Children replace the layout, built from the Field parts, DateFieldGroup and DateInput from Date Field.

Data attributes

AttributePresent when
data-slotAlways: time-field
data-disabledThe field is disabled
data-invalidThe field is invalid
data-readonlyThe field is read-only
data-requiredThe field is required