Date Time Field
An easily stylable date 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 { DateTimeField } from '@base-ui/react/date-time-field';
<DateTimeField.Root>
<DateTimeField.SectionList>
<DateTimeField.Section />
</DateTimeField.SectionList>
<DateTimeField.Clear />
</DateTimeField.Root>Examples
Custom format
Use the format prop to customize the date and time display format. The format string uses tokens from the configured date adapter (date-fns by default). The supported section types are year, month, day, weekday, hours, minutes, seconds, and meridiem.
When using the date-fns adapter, common tokens include:
| Section | Tokens | Example |
|---|---|---|
| Year | y, yy, yyyy | 2024, 24, 2024 |
| Month | M, MM, MMM, MMMM | 1, 01, Jan, January |
| Day | d, dd, do | 5, 05, 5th |
| Weekday | E, EEE, EEEE | T, Tue, Tuesday |
| 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: P through PPPP for dates, p through pppp for times, and combined forms like Pp for date and time together.
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 <DateTimeField.SectionList> to render the clear button next to them using <DateTimeField.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 date and 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 date-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: DateTimeField.Root.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: DateTimeField.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: DateTimeField.Root.State, ) => ReactElement) | undefined
data-disabled
Present when the date-time field is disabled.
data-readonly
Present when the date-time field is readonly.
data-required
Present when the date-time field is required.
data-valid
Present when the date-time field is in valid state (when wrapped in Field.Root).
data-invalid
Present when the date-time field is in invalid state (when wrapped in Field.Root).
data-dirty
Present when the date-time field’s value has changed (when wrapped in Field.Root).
data-touched
Present when the date-time field has been touched (when wrapped in Field.Root).
data-filled
Present when the date-time field is filled (when wrapped in Field.Root).
data-focused
Present when the date-time field is focused (when wrapped in Field.Root).
| Attribute | Description | |
|---|---|---|
data-disabled | Present when the date-time field is disabled. | |
data-readonly | Present when the date-time field is readonly. | |
data-required | Present when the date-time field is required. | |
data-valid | Present when the date-time field is in valid state (when wrapped in Field.Root). | |
data-invalid | Present when the date-time field is in invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the date-time field’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the date-time field has been touched (when wrapped in Field.Root). | |
data-filled | Present when the date-time field is filled (when wrapped in Field.Root). | |
data-focused | Present when the date-time field is focused (when wrapped in Field.Root). | |
DateTimeField.Root.StateHide
type DateTimeFieldRootState = {
/** 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;
}DateTimeField.Root.ActionsHide
type DateTimeFieldRootActions = {
/**
* 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: DateTimeField.Section.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: DateTimeField.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: DateTimeField.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, “/", “-"). | |
DateTimeField.Section.StateHide
type DateTimeFieldSectionState = {
/** 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
DateTimeField.SectionList.PropsHide
Re-Export of SectionList props as DateTimeFieldSectionListProps
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: DateTimeField.Clear.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: DateTimeField.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: DateTimeField.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). | |
DateTimeField.Clear.StateHide
type DateTimeFieldClearState = {
/** 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;
}