Date Input
A segment-based date input that allows users to enter dates by navigating individual date parts.
Anatomy
<DateInput.Root>
<DateInput.Label />
<DateInput.Control>
<DateInput.SegmentGroup>
<DateInput.Segment />
</DateInput.SegmentGroup>
</DateInput.Control>
<DateInput.HiddenInput />
</DateInput.Root>
Examples
Default Value
Set defaultValue with parseDate for the initial date.
Controlled
Use value and onValueChange to control the value.
Root Provider
Use RootProvider with the useDateInput hook to access the state and methods from outside the component.
Granularity
Set granularity to choose which fields show: day, hour, minute or second.
Time Only
Set granularity to minute or second and pass a formatter with only time fields. Set hourCycle to switch
between 12 and 24 hour formats.
Range
Set selectionMode="range" and render two SegmentGroup components with index set to 0 and 1.
Min and Max
Set min and max with parseDate to restrict the range. Dates outside it are marked invalid.
Disabled
Set disabled to block interaction.
Read Only
Set readOnly to prevent edits while keeping the input focusable.
Invalid
Set invalid to show an error state.
Leading Zeros
Set shouldForceLeadingZeros to pad numeric segments with a leading zero.
Localized
Set locale for the language and regional format of the segments.
RTL
Set dir="rtl" for right-to-left languages.
With Clear Button
Call clearValue from useDateInput (via RootProvider) to build a clear button.
With Date Picker
Sync DateInput and DatePicker through onValueChange so users can type a date or pick one from a calendar.
API Reference
Props
Root
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
allSegments | SegmentsThe computed segments map for the formatter. | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
createCalendar | (identifier: CalendarIdentifier) => CalendarA function that creates a calendar object for a given calendar identifier. Use this to support non-Gregorian calendars (e.g., Persian, Islamic, Buddhist). | |
defaultPlaceholderValue | DateValueThe initial placeholder date when rendered. | |
defaultValue | DateValue[]The initial selected date(s) when rendered. Use when you don't need to control the selected date(s). | |
dir | 'ltr' | 'ltr' | 'rtl'The document's text/writing direction. |
disabled | booleanWhether the date input is disabled. | |
form | stringThe `form` attribute of the hidden input element. | |
format | (date: DateValue, details: FormatDateDetails) => stringThe format function for converting a DateValue to a string. | |
formatter | DateFormatterThe date formatter to use. | |
getRootNode | () => ShadowRoot | Node | DocumentA root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. | |
granularity | 'day' | DateGranularityDetermines the smallest unit that is displayed in the date input. |
hideTimeZone | false | booleanWhether to hide the time zone segment when the value is a `ZonedDateTime`. Has no effect for values without a time zone. |
hourCycle | HourCycleWhether to use 12-hour or 24-hour time format. By default, this is determined by the locale. | |
id | stringThe unique identifier of the machine. | |
ids | ElementIdsThe ids of the elements in the date input. Useful for composition. | |
invalid | booleanWhether the date input is invalid | |
isDateUnavailable | (date: DateValue, locale: string) => booleanReturns whether a date is unavailable. When a committed date matches, the input is marked as invalid. | |
locale | 'en-US' | stringThe locale (BCP 47 language tag) to use when formatting the date. |
max | DateValueThe maximum date that can be selected. | |
maxGranularity | 'year' | MaxGranularityDetermines the largest unit that is displayed in the date input. To create a time-only input, set this to `"hour"` and set `granularity` to `"hour"`, `"minute"`, or `"second"`. |
min | DateValueThe minimum date that can be selected. | |
name | stringThe `name` attribute of the input element. | |
onFocusChange | (details: FocusChangeDetails) => voidA function called when the date input gains or loses focus. | |
onPlaceholderChange | (details: PlaceholderChangeDetails) => voidA function called when the placeholder value changes. | |
onValueChange | (details: ValueChangeDetails) => voidFunction called when the value changes. | |
placeholderValue | DateValueThe controlled placeholder date. | |
readOnly | booleanWhether the date input is read-only. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<DateInputRootState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
required | booleanWhether the date input is required | |
selectionMode | 'single' | SelectionModeThe selection mode of the date input. - `single` - only one date can be entered - `range` - a range of dates can be entered (start and end) |
shouldForceLeadingZeros | false | booleanWhether to always show leading zeros in month, day, and hour fields. When false, formatting follows the locale default (e.g. "1" instead of "01"). |
timeZone | 'UTC' | stringThe time zone to use |
translations | IntlTranslationsThe localized messages to use. | |
value | DateValue[]The controlled selected date(s). |
| Attribute | Description |
|---|---|
[data-date-input-root] | <uid> |
[data-disabled] | Present when disabled |
[data-readonly] | Present when read-only |
[data-invalid] | Present when invalid |
[data-focus] | Present when focused |
Control
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<DateInputControlState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-date-input-control] | <uid> |
[data-disabled] | Present when disabled |
[data-readonly] | Present when read-only |
[data-invalid] | Present when invalid |
[data-focus] | Present when focused |
HiddenInput
Defines the <input> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
index | number | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Label
Defines the <label> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-date-input-label] | <uid> |
[data-disabled] | Present when disabled |
[data-readonly] | Present when read-only |
[data-invalid] | Present when invalid |
RootProvider
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
value | DateInputApi<PropTypes> | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<DateInputRootProviderState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
SegmentGroup
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
index | number | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<DateInputSegmentGroupState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-date-input-segment-group] | <uid> |
[data-disabled] | Present when disabled |
[data-readonly] | Present when read-only |
[data-invalid] | Present when invalid |
[data-focus] | Present when focused |
Segment
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
segment | DateSegment | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<DateInputSegmentState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-date-input-segment] | <uid> |
[data-type] | The type of the item |
[data-readonly] | Present when read-only |
[data-disabled] | Present when disabled |
[data-value] | The value of the item |
[data-editable] | |
[data-placeholder-shown] | Present when placeholder is shown |
Context
API
| Property | Type |
|---|---|
focused | booleanWhether the date input is focused |
disabled | booleanWhether the date input is disabled |
invalid | booleanWhether the date input is invalid |
value | DateValue[]The selected date(s). |
valueAsDate | Date[]The selected date(s) as Date objects. |
valueAsString | string[]The selected date(s) as strings. |
placeholderValue | DateValueThe placeholder date. |
displayValues | IncompleteDate[]Per-group editing state. Each IncompleteDate tracks which segments have been filled in by the user (non-null = entered, null = placeholder). |
focus | VoidFunctionFocuses the first segment. |
setValue | (values: DateValue[]) => voidSets the selected date(s) to the given values. |
clearValue | VoidFunctionClears the selected date(s). |
getSegments | (props?: SegmentsProps | undefined) => DateSegment[]Returns the segments for the given index. |
getSegmentState | (props: SegmentProps) => SegmentStateReturns the state details for a given segment. |
getRootState | () => RootStateReturns the state of the root. |
getSegmentGroupState | (props?: SegmentGroupProps | undefined) => SegmentGroupStateReturns the state of a given segment group. |
Accessibility
Complies with the Spinbutton WAI-ARIA design pattern.