Date Input

A segment-based date input that allows users to enter dates by navigating individual date parts.

Loading...

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.

AttributeDefaultType
allSegments
Segments

The computed segments map for the formatter.

asChild
boolean

Use 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) => Calendar

A function that creates a calendar object for a given calendar identifier. Use this to support non-Gregorian calendars (e.g., Persian, Islamic, Buddhist).

defaultPlaceholderValue
DateValue

The 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
boolean

Whether the date input is disabled.

form
string

The `form` attribute of the hidden input element.

format
(date: DateValue, details: FormatDateDetails) => string

The format function for converting a DateValue to a string.

formatter
DateFormatter

The date formatter to use.

getRootNode
() => ShadowRoot | Node | Document

A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron.

granularity'day'
DateGranularity

Determines the smallest unit that is displayed in the date input.

hideTimeZonefalse
boolean

Whether to hide the time zone segment when the value is a `ZonedDateTime`. Has no effect for values without a time zone.

hourCycle
HourCycle

Whether to use 12-hour or 24-hour time format. By default, this is determined by the locale.

id
string

The unique identifier of the machine.

ids
ElementIds

The ids of the elements in the date input. Useful for composition.

invalid
boolean

Whether the date input is invalid

isDateUnavailable
(date: DateValue, locale: string) => boolean

Returns whether a date is unavailable. When a committed date matches, the input is marked as invalid.

locale'en-US'
string

The locale (BCP 47 language tag) to use when formatting the date.

max
DateValue

The maximum date that can be selected.

maxGranularity'year'
MaxGranularity

Determines 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
DateValue

The minimum date that can be selected.

name
string

The `name` attribute of the input element.

onFocusChange
(details: FocusChangeDetails) => void

A function called when the date input gains or loses focus.

onPlaceholderChange
(details: PlaceholderChangeDetails) => void

A function called when the placeholder value changes.

onValueChange
(details: ValueChangeDetails) => void

Function called when the value changes.

placeholderValue
DateValue

The controlled placeholder date.

readOnly
boolean

Whether 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
boolean

Whether the date input is required

selectionMode'single'
SelectionMode

The selection mode of the date input. - `single` - only one date can be entered - `range` - a range of dates can be entered (start and end)

shouldForceLeadingZerosfalse
boolean

Whether 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'
string

The time zone to use

translations
IntlTranslations

The localized messages to use.

value
DateValue[]

The controlled selected date(s).

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

AttributeDefaultType
asChild
boolean

Use 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.

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

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDefaultType
asChild
boolean

Use 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.

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

AttributeDefaultType
value
DateInputApi<PropTypes>

asChild
boolean

Use 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.

AttributeDefaultType
asChild
boolean

Use 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.

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

AttributeDefaultType
segment
DateSegment

asChild
boolean

Use 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.

AttributeDescription
[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

PropertyType
focused
boolean

Whether the date input is focused

disabled
boolean

Whether the date input is disabled

invalid
boolean

Whether 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
DateValue

The 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
VoidFunction

Focuses the first segment.

setValue
(values: DateValue[]) => void

Sets the selected date(s) to the given values.

clearValue
VoidFunction

Clears the selected date(s).

getSegments
(props?: SegmentsProps | undefined) => DateSegment[]

Returns the segments for the given index.

getSegmentState
(props: SegmentProps) => SegmentState

Returns the state details for a given segment.

getRootState
() => RootState

Returns the state of the root.

getSegmentGroupState
(props?: SegmentGroupProps | undefined) => SegmentGroupState

Returns the state of a given segment group.

Accessibility

Complies with the Spinbutton WAI-ARIA design pattern.