Time Field
A time input with hour, minute and day-period segments that follow the locale.
Installation
npx shadcn@latest add @oakoss/time-fieldUsage
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.
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
| Attribute | Present when |
|---|---|
data-slot | Always: time-field |
data-disabled | The field is disabled |
data-invalid | The field is invalid |
data-readonly | The field is read-only |
data-required | The field is required |