DatePicker

AI Tip Want to skip the docs? Use the MCP Server

A date picker allows users to select a single date from a calendar.

Usage

Value

A DatePicker displays a placeholder by default. An initial, uncontrolled value can be provided to the DatePicker using the defaultValue prop. Alternatively, a controlled value can be provided using the value prop.

Date values are provided using objects in the @internationalized/date package. This library handles correct international date manipulation across calendars, time zones, and other localization concerns. DatePicker supports values of the following types:

  • CalendarDate – a date without any time components. May be parsed from a string representation using the parseDate function. Use this type to represent dates where the time is not important, such as a birthday or an all day calendar event.
  • CalendarDateTime – a date with a time, but not in any specific time zone. May be parsed from a string representation using the parseDateTime function. Use this type to represent times that occur at the same local time regardless of the time zone, such as the time of New Years Eve fireworks which always occur at midnight. Most times are better stored as a ZonedDateTime.
  • ZonedDateTime – a date with a time in a specific time zone. May be parsed from a string representation using the parseZonedDateTime, parseAbsolute, or parseAbsoluteToLocal functions. Use this type to represent an exact moment in time at a particular location on Earth.

Controlled

A DatePicker can handle value state in controlled mode.

Validation

Invalid

A DatePicker can be marked as invalid.

Min and Max

The minValue and maxValue props can be used to limit the range of dates that a user can select.

Unavailable Dates

DatePicker supports marking certain dates as unavailable. These dates remain focusable with the keyboard in the calendar so that navigation is consistent, but cannot be selected by the user. When an unavailable date is entered into the date field, it is marked as invalid. The isDateUnavailable prop accepts a callback that is called to evaluate whether each visible date is unavailable.

This example includes multiple unavailable date ranges, e.g. dates when no appointments are available. In addition, all weekends are unavailable. The minValue prop is also used to prevent selecting dates before today.

Custom Validation

The validate function can be used to perform custom validation logic. It receives the current date value, and should return a string or array of strings representing one or more error messages if the value is invalid.

This example validates that the selected date is a weekday and not a weekend according to the current locale.

Description

The description prop can be used to provide additional context about the DatePicker.

Props

isFluid?

If true, the DatePicker will take all available width.

Defaults to false.
inputRef?

A ref for the HTML input element.

inputGroupProps?

The props for the InputGroup.

maxVisibleMonths?

The maximum number of months to display at once in the calendar popover, if screen space permits.

Defaults to 1.
isFixedWeeks?

Whether the calendar should always display 6 weeks. This ensures that the height of the popover does not change between months, causing layout shifts.

Defaults to true.
popoverProps?

The props for the popover.

calendarProps?

The props for the calendar.

form?

The element to associate the input with. The value of this attribute must be the id of a in the same document. See MDN.

style?

The inline style for the element. A function may be provided to compute the style based on component state.

validationBehavior?

Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA.

Defaults to 'native'.
autoComplete?

Describes the type of autocomplete functionality the input should provide if any. See MDN.

pageBehavior?

Controls the behavior of paging. Pagination either works by advancing the visible page by visibleDuration (default) or one unit of visibleDuration.

Defaults to visible.
firstDayOfWeek?

The day that starts the week.

minValue?

The minimum allowed date that a user may select.

maxValue?

The maximum allowed date that a user may select.

isDateUnavailable?

Callback that is called for each date of the calendar. If it returns true, then the date is unavailable.

placeholderValue?

A placeholder date that influences the format of the placeholder shown when no value is selected. Defaults to today's date at midnight.

hideTimeZone?

Whether to hide the time zone abbreviation.

Defaults to false.
shouldForceLeadingZeros?

Whether to always show leading zeros in the month, day, and hour fields. By default, this is determined by the user's locale.

isDisabled?

Whether the input is disabled.

isReadOnly?

Whether the input can be selected but not changed by the user.

isRequired?

Whether user input is required on the input before form submission.

isInvalid?

Whether the input value is invalid.

validate?

A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if validationBehavior="native". For realtime validation, use the isInvalid prop instead.

autoFocus?

Whether the element should receive focus on render.

isOpen?

Whether the overlay is open by default (controlled).

defaultOpen?

Whether the overlay is open by default (uncontrolled).

value?

The current value (controlled).

defaultValue?

The default value (uncontrolled).

name?

The name of the input element, used when submitting an HTML form. See MDN.

shouldCloseOnSelect?

Determines whether the date picker popover should close automatically when a date is selected.

Defaults to true.
className?

The CSS className for the element. A function may be provided to compute the class based on component state.

dir?
lang?
inert?
translate?
createCalendar?

A function to create a new Calendar object for a given calendar identifier. If not provided, the createCalendar function from @internationalized/date will be used.

description?

The helper message of the field.

errorMessage?

The error message of the field.

label?

The label of the field.

necessityIndicator?

Whether the required state should be shown as an asterisk or a label, which would display (Optional) on all non required field labels.

size?

A Field can vary in size.

Defaults to md.
contextualHelp?

A ContextualHelp element to place next to the label.