Time Field
An easily stylable time field component.
View as MarkdownUsage guidelines
- Form controls must have an accessible name: It can be created using a
<label>element or theFieldcomponent. See the forms guide.
Anatomy
Import the component and assemble its parts:
import { TimeField } from '@base-ui/react/time-field';
<TimeField.Root>
<TimeField.SectionList>
<TimeField.Section />
</TimeField.SectionList>
<TimeField.Clear />
</TimeField.Root>Examples
Custom format
Use the format prop to customize the time display format. The format string uses tokens from the configured date adapter (date-fns by default). The supported section types are hours, minutes, seconds, and meridiem.
When using the date-fns adapter, common tokens include:
| Section | Tokens | Example |
|---|---|---|
| Hours (24h) | H, HH | 9, 09 |
| Hours (12h) | h, hh | 9, 09 |
| Minutes | m, mm | 5, 05 |
| Seconds | s, ss | 8, 08 |
| Meridiem | a, aa, aaa | AM |
The adapter also supports locale-aware meta tokens that expand to localized time patterns: p (short), pp (medium), ppp (long), and pppp (full).
See the date-fns format reference for the full token list. Not all date-fns tokens are supported — only those that map to the section types listed above.
Clear button
Wrap the sections in <TimeField.SectionList> to render the clear button next to them using <TimeField.Clear>. The SectionList groups all sections into a single element so that additional controls can be placed alongside them inside the field.
Validation
Use the min and max props to constrain the allowed time range. Combine with <Field.Error> to display validation messages.
Localization
Use <LocalizationProvider> to set the locale and customize placeholder text via the translations prop.
API reference
Root
Groups all parts of the time field.
Renders a <div> element and a hidden <input> beside.
namestring—
- Name
- Description
Identifies the field when a form is submitted.
- Type
string | undefined
defaultValueTemporalValue—
- Name
- Description
The uncontrolled value that should be initially selected. To render a controlled temporal field, use the
valueprop instead.- Type
TemporalValue | undefined
valueTemporalValue—
- Name
- Description
The controlled value that should be selected. To render an uncontrolled temporal field, use the
defaultValueprop instead.- Type
TemporalValue | undefined
onValueChangefunction—
- Name
- Description
Event handler called when the selected value changes. Provides the new value as an argument.
- Type
| (( value: TemporalValue, eventDetails: TemporalFieldValueChangeEventDetails, ) => void) | undefined
actionsRefReact.RefObject<TemporalFieldRootActions | null>—
- Name
- Description
A ref to imperative actions.
clear: Clears the field value.
- Type
| React.RefObject<TemporalFieldRootActions | null> | undefined
ampmbooleanbased on the current locale
- Name
- Description
Whether to use 12-hour format with AM/PM or 24-hour format. Is ignored if a custom format is provided.
- Type
boolean | undefined- Default
based on the current locale
referenceDateDate'The closest valid date using the validation props.'
- Name
- Description
The date used to generate the new value when both
valueanddefaultValueare empty.- Type
Date | undefined- Default
'The closest valid date using the validation props.'
timezonestring'The timezone of the "value" or "defaultValue" prop if defined, "default" otherwise.'
- Name
- Description
Choose which timezone to use for the value. Example: “default”, “system”, “UTC”, “America/New_York”. If you pass values from other timezones to some props, they will be converted to this timezone before being used.
- Type
string | undefined- Default
'The timezone of the "value" or "defaultValue" prop if defined, "default" otherwise.'
stepnumber1
- Name
- Description
The step increment for the most granular section of the field. For example, with format ‘HH:mm’ and step=5, pressing ArrowUp on the minutes section will increment by 5 (for example, 10 -> 15 -> 20).
- Type
number | undefined- Default
1
minDate—
- Name
- Description
Minimal selectable date.
- Type
Date | undefined
maxDate—
- Name
- Description
Maximal selectable date.
- Type
Date | undefined
formatstring—
- Name
- Description
Format of the value when rendered in the field. Only tokens that map to the supported section types (year, month, day, weekday, hours, minutes, seconds, meridiem) are recognized — other tokens are treated as literal text.
- Type
string | undefined
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
readOnlybooleanfalse
- Name
- Description
Whether the user should be unable to change the field value.
- Type
boolean | undefined- Default
false
requiredbooleanfalse
- Name
- Description
Whether the user must enter a value before submitting a form.
- Type
boolean | undefined- Default
false
inputRefReact.Ref<HTMLInputElement>—
- Name
- Description
A ref to access the hidden input element.
- Type
React.Ref<HTMLInputElement> | undefined
children| React.ReactNode
| ((section: TemporalFieldSection, index: number) => React.ReactNode)—
| ((section: TemporalFieldSection, index: number) => React.ReactNode)
- Name
- Description
The children of the component. If a function is provided, it will be called with each section and must render a
DateField.Section(or the correspondingTimeField.Section/DateTimeField.Section) for each one. Custom wrapper elements may be added around the sections.- Type
| React.ReactNode | (( section: TemporalFieldSection, index: number, ) => React.ReactNode) | undefined
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: TimeField.Root.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: TimeField.Root.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: TimeField.Root.State, ) => ReactElement) | undefined
data-disabled
Present when the time field is disabled.
data-readonly
Present when the time field is readonly.
data-required
Present when the time field is required.
data-valid
Present when the time field is in valid state (when wrapped in Field.Root).
data-invalid
Present when the time field is in invalid state (when wrapped in Field.Root).
data-dirty
Present when the time field’s value has changed (when wrapped in Field.Root).
data-touched
Present when the time field has been touched (when wrapped in Field.Root).
data-filled
Present when the time field is filled (when wrapped in Field.Root).
data-focused
Present when the time field is focused (when wrapped in Field.Root).
| Attribute | Description | |
|---|---|---|
data-disabled | Present when the time field is disabled. | |
data-readonly | Present when the time field is readonly. | |
data-required | Present when the time field is required. | |
data-valid | Present when the time field is in valid state (when wrapped in Field.Root). | |
data-invalid | Present when the time field is in invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the time field’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the time field has been touched (when wrapped in Field.Root). | |
data-filled | Present when the time field is filled (when wrapped in Field.Root). | |
data-focused | Present when the time field is focused (when wrapped in Field.Root). | |
TimeField.Root.StateHide
type TimeFieldRootState = {
/** Whether the user must enter a value before submitting a form. */
required: boolean;
/** Whether the component should ignore user interaction. */
disabled: boolean;
/** Whether the user should be unable to change the field value. */
readOnly: boolean;
/** Whether the field has been touched. */
touched: boolean;
/** Whether the field value has changed from its initial value. */
dirty: boolean;
/** Whether the field is valid. */
valid: boolean | null;
/** Whether the field has a value. */
filled: boolean;
/** Whether the field is focused. */
focused: boolean;
}TimeField.Root.ActionsHide
type TimeFieldRootActions = {
/**
* Clears the field value.
* If the value is already empty, it clears the sections (visual placeholders).
*/
clear: () => void;
}Section
Renders the content of a temporal field’s section.
Renders a <div> element.
section*TemporalFieldSection
—
TemporalFieldSection- Name
- Description
The section to render.
- Type
TemporalFieldSection
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: TimeField.Section.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: TimeField.Section.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: TimeField.Section.State, ) => ReactElement) | undefined
data-empty
Present when the section value is empty.
data-section-index
Index of the section in the field.
data-separator
Present when the section is a separator (for example, “/", “-").
| Attribute | Description | |
|---|---|---|
data-empty | Present when the section value is empty. | |
data-section-index | Index of the section in the field. | |
data-separator | Present when the section is a separator (for example, “/", “-"). | |
TimeField.Section.StateHide
type TimeFieldSectionState = {
/** Index of the section in the field. */
sectionIndex: number;
/** Whether the section is empty. */
empty: boolean;
/** Whether the section is a separator (for example, "/", "-"). */
separator: boolean;
}SectionList
Renders all sections of a temporal field. Doesn’t render its own HTML element.
children*(
section: TemporalFieldSection,
index: number,
) => React.ReactNode
—
(
section: TemporalFieldSection,
index: number,
) => React.ReactNode- Name
- Description
A function that receives each section and must render a
DateField.Section(or the corresponding field-type alias) for it.- Type
( section: TemporalFieldSection, index: number, ) => React.ReactNode
TimeField.SectionList.PropsHide
Re-Export of SectionList props as TimeFieldSectionListProps
Clear
Clears the field value when clicked.
Renders a <button> element.
nativeButtonbooleantrue
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (for example,<div>).- Type
boolean | undefined- Default
true
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: TimeField.Clear.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: TimeField.Clear.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: TimeField.Clear.State, ) => ReactElement) | undefined
data-disabled
Present when the button is disabled.
data-readonly
Present when the field is read-only.
data-empty
Present when the field value is empty (all sections are empty).
| Attribute | Description | |
|---|---|---|
data-disabled | Present when the button is disabled. | |
data-readonly | Present when the field is read-only. | |
data-empty | Present when the field value is empty (all sections are empty). | |
TimeField.Clear.StateHide
type TimeFieldClearState = {
/** Whether the component should ignore user interaction. */
disabled: boolean;
/** Whether the field value is empty (all sections are empty). */
empty: boolean;
/** Whether the field is read-only. */
readOnly: boolean;
}