Skip to contents

Date Field

An easily stylable date field component.

View as Markdown
MM
DD
YYYY

Usage guidelines

  • Form controls must have an accessible name: It can be created using a <label> element or the Field component. See the forms guide.

Anatomy

Import the component and assemble its parts:

Anatomy

Examples

Custom format

Use the format prop to customize the date display format. The format string uses tokens from the configured date adapter (date-fns by default). The supported section types are year, month, day, and weekday.

When using the date-fns adapter, common tokens include:

SectionTokensExample
Yeary, yy, yyyy2024, 24, 2024
MonthM, MM, MMM, MMMM1, 01, Jan, January
Dayd, dd, do5, 05, 5th
WeekdayE, EEE, EEEET, Tue, Tuesday

The adapter also supports locale-aware meta tokens that expand to localized date 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.

MM
DD
YYYY
EEEE
MMMM
DD
YYYY
YYYY
MM
DD

Clear button

Wrap the sections in <DateField.SectionList> to render the clear button next to them using <DateField.Clear>. The SectionList groups all sections into a single element so that additional controls can be placed alongside them inside the field.

MM
DD
YYYY

Validation

Use the min and max props to constrain the allowed date range. Combine with <Field.Error> to display validation messages.

MM
DD
YYYY

Localization

Use <LocalizationProvider> to set the locale and customize placeholder text via the translations prop.

JJ
MM
AAAA
TT
MM
JJJJ

API reference

Root

Groups all parts of the date field. Renders a <div> element and a hidden <input> beside.

namestring
Name
Description

Identifies the field when a form is submitted.

Type
defaultValueTemporalValue
Description

The uncontrolled value that should be initially selected. To render a controlled temporal field, use the value prop instead.

Type
valueTemporalValue
Name
Description

The controlled value that should be selected. To render an uncontrolled temporal field, use the defaultValue prop instead.

Type
onValueChangefunction
Description

Event handler called when the selected value changes. Provides the new value as an argument.

Type
actionsRefReact.RefObject<TemporalFieldRootActions | null>
Description

A ref to imperative actions.

  • clear: Clears the field value.
Type
referenceDateDate'The closest valid date using the validation props.'
Description

The date used to generate the new value when both value and defaultValue are empty.

Type
Default
'The closest valid date using the validation props.'
timezonestring'The timezone of the "value" or "defaultValue" prop if defined, "default" otherwise.'
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
Default
'The timezone of the "value" or "defaultValue" prop if defined, "default" otherwise.'
minDate
Name
Description

Minimal selectable date.

Type
maxDate
Name
Description

Maximal selectable date.

Type
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
disabledbooleanfalse
Description

Whether the component should ignore user interaction.

Type
Default
false
readOnlybooleanfalse
Description

Whether the user should be unable to change the field value.

Type
Default
false
requiredbooleanfalse
Description

Whether the user must enter a value before submitting a form.

Type
Default
false
inputRefReact.Ref<HTMLInputElement>
Description

A ref to access the hidden input element.

Type
children| React.ReactNode
| ((section: TemporalFieldSection, index: number) => React.ReactNode)
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 corresponding TimeField.Section / DateTimeField.Section) for each one. Custom wrapper elements may be added around the sections.

Type
classNamestring | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function
Name
Type
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 ReactElement or a function that returns the element to render.

Type
data-disabled

Present when the date field is disabled.

data-readonly

Present when the date field is readonly.

data-required

Present when the date field is required.

data-valid

Present when the date field is in valid state (when wrapped in Field.Root).

data-invalid

Present when the date field is in invalid state (when wrapped in Field.Root).

data-dirty

Present when the date field’s value has changed (when wrapped in Field.Root).

data-touched

Present when the date field has been touched (when wrapped in Field.Root).

data-filled

Present when the date field is filled (when wrapped in Field.Root).

data-focused

Present when the date field is focused (when wrapped in Field.Root).

AttributeDescription
data-disabled

Present when the date field is disabled.

data-readonly

Present when the date field is readonly.

data-required

Present when the date field is required.

data-valid

Present when the date field is in valid state (when wrapped in Field.Root).

data-invalid

Present when the date field is in invalid state (when wrapped in Field.Root).

data-dirty

Present when the date field’s value has changed (when wrapped in Field.Root).

data-touched

Present when the date field has been touched (when wrapped in Field.Root).

data-filled

Present when the date field is filled (when wrapped in Field.Root).

data-focused

Present when the date field is focused (when wrapped in Field.Root).

DateField.Root.PropsHide

Re-Export of Root props as DateFieldRootProps

DateField.Root.StateHide

DateField.Root.ActionsHide

Section

Renders the content of a temporal field’s section. Renders a <div> element.

section*
Description

The section to render.

Type
classNamestring | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function
Name
Type
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 ReactElement or a function that returns the element to render.

Type
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, “/", “-").

AttributeDescription
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, “/", “-").

DateField.Section.PropsHide

Re-Export of Section props as DateFieldSectionProps

DateField.Section.StateHide

SectionList

Renders all sections of a temporal field. Doesn’t render its own HTML element.

children*
Description

A function that receives each section and must render a DateField.Section (or the corresponding field-type alias) for it.

Type

DateField.SectionList.PropsHide

Re-Export of SectionList props as DateFieldSectionListProps

Clear

Clears the field value when clicked. Renders a <button> element.

nativeButtonbooleantrue
Description

Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).

Type
Default
true
disabledbooleanfalse
Description

Whether the component should ignore user interaction.

Type
Default
false
classNamestring | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function
Name
Type
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 ReactElement or a function that returns the element to render.

Type
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).

AttributeDescription
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).

DateField.Clear.PropsHide

Re-Export of Clear props as DateFieldClearProps

DateField.Clear.StateHide