apps/www/content/docs/components/date-picker.mdx
import { DatePicker } from "@chakra-ui/react"
<DatePicker.Root>
<DatePicker.Label />
<DatePicker.Control>
<DatePicker.Input />
<DatePicker.IndicatorGroup>
<DatePicker.Trigger>
<LuCalendar />
</DatePicker.Trigger>
</DatePicker.IndicatorGroup>
</DatePicker.Control>
<Portal>
<DatePicker.Positioner>
<DatePicker.Content>
<DatePicker.View view="day">
<DatePicker.Header />
<DatePicker.DayTable />
</DatePicker.View>
<DatePicker.View view="month">
<DatePicker.Header />
<DatePicker.MonthTable />
</DatePicker.View>
<DatePicker.View view="year">
<DatePicker.Header />
<DatePicker.YearTable />
</DatePicker.View>
</DatePicker.Content>
</DatePicker.Positioner>
</Portal>
</DatePicker.Root>
Date values are provided using objects from
@internationalized/date,
which handles timezone-safe, locale-aware date handling.
This will be replaced by the Temporal API when it's widely supported in browsers.
Use the size prop to change the size of the date picker.
Use the variant prop to change the visual style of the date picker.
Use the disabled prop to prevent user interaction with the date picker.
Use the readOnly prop to prevent modification while keeping the value visible.
Use the defaultView prop to set the initial calendar view to "day",
"month", or "year".
Use the defaultValue prop to set the initially selected date.
Use the value and onValueChange props to control the selected date.
An alternative way to control the date picker is to use the RootProvider
component and the useDatePicker store hook.
Set the selectionMode prop to "range" to allow selecting a start and end
date.
Set the selectionMode prop to "multiple" to allow selecting multiple dates.
Set the defaultView and minView props to "month" to restrict the picker to
month selection only.
Set the selectionMode prop to "range" and minView to "month" to select a
month range.
Set the defaultView and minView props to "year" to restrict the picker to
year selection only.
Set the selectionMode prop to "range" and minView to "year" to select a
year range.
Use the min and max props to restrict date selection to a specific range.
Use the isDateUnavailable prop to disable specific dates (e.g., weekends,
holidays).
Use the format and parse props to control how dates are displayed and
interpreted.
Use the locale prop to display the calendar in different languages and
regional formats.
Replace the default trigger with a styled custom button.
<ExampleTabs name="date-picker-with-button" />Place the trigger icon outside the input field.
<ExampleTabs name="date-picker-with-outside-icon" />Integrate with InputGroup for custom input layouts with start/end elements.
<ExampleTabs name="date-picker-with-input-group" />Add a clear trigger to reset the selection.
<ExampleTabs name="date-picker-with-clear" />Use the positioning prop to control the placement of the calendar popover.
Here's an example of customizing the header layout with RangeText and
navigation buttons.
Render the DatePicker.MonthSelect and DatePicker.YearSelect components for
quick month/year navigation.
Use the numOfMonths prop to display multiple months side by side.
Render the DatePicker.PresetTrigger component to provide quick date selection
options.
Here's an example of a task-management style picker with presets sidebar and calendar side by side.
<ExampleTabs name="date-picker-with-presets-sidebar" />Here's an example of adding a footer button to quickly jump to today's date.
<ExampleTabs name="date-picker-with-today-button" />Here's an example of combining date selection with a time input for datetime picking.
<ExampleTabs name="date-picker-with-time" />Here's an example of integrating with native form validation.
<ExampleTabs name="date-picker-form" />Here's an example of integrating with react-hook-form using the Controller
pattern.
Use the fixedWeeks prop to always display 6 weeks in the calendar, ensuring a
consistent height regardless of the month.
Use the openOnClick prop to open the calendar when clicking the input field,
removing the need for a separate trigger button.
The DatePicker does not natively integrate with the Field component yet. Use
Field.Context to wire up the field state manually. Native support will be
added in a future version.
Explore the DatePicker component parts interactively. Click on parts in the
sidebar to highlight them in the preview.