import { Time } from "@internationalized/date";
import { TimeField } from "@senvenli/react/date";
export default function Example() {
return <TimeField label="Opens at" defaultValue={new Time(9, 0)} />;
}import { TimeField } from "@senvenli/react/date";Examples
Minute steps and a 24-hour clock
Arrow keys move the minutes a quarter of an hour at a time.import { Time } from "@internationalized/date";
import { TimeField } from "@senvenli/react/date";
export default function Example() {
return (
<TimeField
label="Delivery cutoff"
description="Orders placed later ship the next day."
hourCycle={24}
minuteStep={15}
defaultValue={new Time(16, 30)}
minValue={new Time(12, 0)}
maxValue={new Time(20, 0)}
/>
);
}In another time zone
The zone is named after the time when it differs from the visitor's, so the label appears once the page runs in the browser.import { Time } from "@internationalized/date";
import { TimeField } from "@senvenli/react/date";
export default function Example() {
return <TimeField label="Pickup time" description="The store's local time." timeZone="Europe/Lisbon" defaultValue={new Time(10, 0)} />;
}Guidelines
When to use it
- Typing a time of day.
Use something else when
- Only certain times are available: a card RadioGroup of them (see its time-slots example). Radio group
Accessibility
Keyboard
| Keys | What happens |
|---|---|
| Arrow up / down | Changes the focused part. |
Built in
- Required fields show "Fill in this field."; a partly typed date says what is missing.
You provide
- A visible label.
API reference
TimeField
| Prop | Type | Default | Description |
|---|---|---|---|
labelRequired | React.ReactNode | – | Always given; the label sits above the field and names its segments. |
description | React.ReactNode | – | |
errorMessage | React.ReactNode | – | What happened and what to do; shown when the field is invalid. |
isRequired | boolean | – | |
requiredValidation | RequiredValidation | – | Who says an empty required field is missing: |
isOptional | boolean | – | Shows "(optional)" when most of the form is required. |
isDisabled | boolean | – | |
isReadOnly | boolean | – | |
isInvalid | boolean | – | Marks the field invalid from outside (a server error); |
id | string | – | The id of the field's first typed segment (day, or the locale's first part), the element that takes focus : |
name | string | – | The form field name; the value is submitted as an ISO string. |
autoFocus | boolean | – | |
onBlur | (event: FocusEvent<Element, Element>) => void | – | |
value | TimeValue | – | A time, or a zoned date-time when a location's zone travels with it. While the user leaves a time typed in part ("10:––"), the field reports |
defaultValue | TimeValue | – | |
onChange | (value: TimeValue | null) => void | – | |
hourCycle | 12 | 24 | – | 24-hour in tr and me, 12-hour in en-US; from the locale unless set. |
granularity | "hour" | "minute" | – | |
minuteStep | number | – | Arrow keys step the minutes by this much (15 or 30). |
timeZone | string | – | The location's zone (IANA, "Europe/Lisbon"). Named after the time when it differs from the user's. |
minValue | TimeValue | – | |
maxValue | TimeValue | – | |
validate | (value: TimeValue | null) => string | true | string[] | null | undefined | – |
labelRequiredReact.ReactNodeAlways given; the label sits above the field and names its segments.
descriptionReact.ReactNodeerrorMessageReact.ReactNodeWhat happened and what to do; shown when the field is invalid.
isRequiredbooleanrequiredValidationRequiredValidationWho says an empty required field is missing:
field(default) orapp. Withappa DS Form'sonSubmitruns with the field empty, and the app's own error must clear on change. See {@link RequiredValidation} for the whole contract.isOptionalbooleanShows "(optional)" when most of the form is required.
isDisabledbooleanisReadOnlybooleanisInvalidbooleanMarks the field invalid from outside (a server error);
errorMessagesays why.idstringThe id of the field's first typed segment (day, or the locale's first part), the element that takes focus :
document.getElementById(id).focus()puts the user in the field, as a focus-on-error does. The field's group gets an id of its own. Left out, the DOM is as before.namestringThe form field name; the value is submitted as an ISO string.
autoFocusbooleanonBlur(event: FocusEvent<Element, Element>) => voidvalueTimeValueA time, or a zoned date-time when a location's zone travels with it.
While the user leaves a time typed in part ("10:––"), the field reports
onChange(null)and keeps the typed parts on screen, so settingnullchanges nothing: the value already is null. To clear the field (an app's own "Temizle" or form reset), give it a newkeyalong with the value: React remounts it empty, or at the value given .defaultValueTimeValueonChange(value: TimeValue | null) => voidhourCycle12 | 2424-hour in tr and me, 12-hour in en-US; from the locale unless set.
granularity"hour" | "minute"minuteStepnumberArrow keys step the minutes by this much (15 or 30).
timeZonestringThe location's zone (IANA, "Europe/Lisbon"). Named after the time when it differs from the user's.
minValueTimeValuemaxValueTimeValuevalidate(value: TimeValue | null) => string | true | string[] | null | undefined