--- title: DatePicker description: "`DatePicker` is a component used for users to select a date." links: - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/date-picker - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-datepicker--basic --- # DatePicker `DatePicker` is a component used for users to select a date. ```tsx ``` ## Usage ```tsx import { DatePicker } from "@yamada-ui/react" ``` ```tsx import { DatePicker } from "@/components/ui" ``` ```tsx import { DatePicker } from "@workspaces/ui" ``` ```tsx ``` :::tip If you want users to view or select a date from an always-visible calendar, use [Calendar](https://yamada-ui.com/docs/components/calendar.md). ::: ### Change Variant ```tsx {(variant, index) => ( )} ``` ### Change Size ```tsx preview {(size, index) => ( )} ``` ### Change Color Scheme ```tsx {(colorScheme, index) => ( new Date(new Date().setDate(1))} /> )} ``` ### Change Format To change the format, set the `format` object. ```tsx const format = useMemo( () => ({ input: null, month: "long", weekday: "narrow", year: "2-digit", }), [], ) return ``` ### Set Default Date To set a default date, set `defaultValue` to a `Date`. ```tsx ``` ### Set Default Input Value To set a default input value, specify a string for `defaultInputValue`. ```tsx ``` ### Set Default Month To set a default month, set `defaultMonth` to a `Date`. ```tsx ``` ### Set Minimum Date To set the minimum selectable date, set `minDate` to a `Date`. ```tsx const [minDate] = useState(() => new Date(new Date().setDate(1))) return ``` ### Set Maximum Date To set the maximum selectable date, set `maxDate` to a `Date`. ```tsx const [maxDate] = useState(() => new Date(new Date().setDate(18))) return ``` ### Allow Values Outside Minimum and Maximum Range By default, if a date outside the minimum and maximum range is entered, it is automatically replaced with the minimum or maximum date. To disable this control and allow values outside the range, set `allowInputBeyond` to `true`. ```tsx const [minDate] = useState(() => new Date(new Date().setDate(1))) const [maxDate] = useState(() => new Date(new Date().setDate(18))) return ``` ### Disable Today Highlighting To disable highlighting of today's date, set `today` to `false`. ```tsx ``` ### Disable Specific Days of the Week To disable specific days of the week, set `excludeDate` to a condition function. ```tsx [0, 1, 6].includes(date.getDay())} /> ``` ### Enable Multiple Selection To enable multiple date selection, set `multiple` to `true`. ```tsx ``` ### Set Maximum for Multiple Selection To set the maximum number of selectable dates in multiple selection, set `max` to a number. ```tsx ``` ### Change Separator To change the separator, specify a string for `separator`. By default, `,` is set. ```tsx ``` ### Enable Range Selection To enable range selection, set `range` to `true`. ```tsx ``` ### Change Start Day of Week To change the start day of the week, set `startDayOfWeek` to `"sunday"` or `"monday"`. ```tsx ``` ### Change Weekend Days To change which days are treated as weekends, set `weekendDays` to an array of days(numbers). ```tsx ``` ### Set Pattern To set a pattern, set a regular expression to `pattern`. ```tsx new Date()} /> ``` ### Handle Parsing of Entered Values To handle the parsing of entered values, use `parseDate`. ```tsx new Date(value)} /> ``` ### Set Holidays To set holidays, set `holidays` to an array of `Date`s. ```tsx const holidays = useMemo( () => [ new Date("2025-01-01"), new Date("2025-01-13"), new Date("2025-02-11"), new Date("2025-02-23"), new Date("2025-02-24"), new Date("2025-03-20"), new Date("2025-04-29"), new Date("2025-05-03"), new Date("2025-05-04"), new Date("2025-05-05"), new Date("2025-05-06"), new Date("2025-07-21"), new Date("2025-08-11"), new Date("2025-09-15"), new Date("2025-09-23"), new Date("2025-10-13"), new Date("2025-11-03"), new Date("2025-11-23"), new Date("2025-11-24"), new Date("2026-01-01"), new Date("2026-01-12"), new Date("2026-02-11"), new Date("2026-02-23"), new Date("2026-03-20"), new Date("2026-04-29"), new Date("2026-05-03"), new Date("2026-05-04"), new Date("2026-05-05"), new Date("2026-05-06"), new Date("2026-07-20"), new Date("2026-08-11"), new Date("2026-09-21"), new Date("2026-09-22"), new Date("2026-10-12"), new Date("2026-11-03"), new Date("2026-11-23"), ], [], ) return ``` ### Hide Outside the Current Month To hide dates outside the current month, set styles using `dayProps`. ```tsx ``` ### Change Offset To change the offset, specify a value for `gutter` or `offset`. ```tsx ``` ### Change Animation To change the animation, specify `"block-start"` or `"inline-end"` for `animationScheme`. By default, `"scale"` is set. ```tsx ``` ### Change Placement To change the placement, specify `"end"` or `"start-center"` for `placement`. By default, `"end-start"` is set. ```tsx ``` ### Blocking Scroll To block scrolling, set `blockScrollOnMount` to `true`. ```tsx ``` ### Close Dropdown On Scroll To close the dropdown on scroll, set `closeOnScroll` to `true`. ```tsx ``` ### Handle opening the dropdown on change To handle the event of opening the dropdown on change, set a function to `openOnChange`. ```tsx ev.target.value.length > 1} /> ``` ### Handle closing the dropdown on change To handle the event of closing the dropdown on change, set a function to `closeOnChange`. ```tsx !ev.target.value.length} /> ``` ### Disable Open Dropdown On Focus To disable opening the dropdown on focus, set `openOnFocus` to `false`. ```tsx ``` ### Disable Open Dropdown On Click To disable opening the dropdown on click, set `openOnClick` to `false`. ```tsx ``` ### Disable Focus After Clear To disable focus after clear, set `focusOnClear` to `false`. ```tsx ``` ### Disable Close On Select To disable closing the dropdown on select, set `closeOnSelect` to `false`. ```tsx ``` ### Disable Close On Outside Click To disable closing dropdown when clicking outside, set `closeOnBlur` to `false`. ```tsx ``` ### Disable Close On Esc To disable closing the dropdown with the Esc key, set `closeOnEsc` to `false`. ```tsx ``` ### Disable Clear Button To disable the clear button, set `clearable` to `false`. ```tsx ``` ### Disallow Input To disallow input, set `allowInput` to `false`. ```tsx ``` ### Change Shape ```tsx {(shape, index) => ( ({ end: new Date(new Date().setDate(new Date().getDate() + 4)), start: new Date(), })} range calendarProps={{ shape }} /> )} ``` ### Disable To disable, set `disabled` to `true`. ```tsx {(variant, index) => ( )} ``` ### Read-Only To make read-only, set `readOnly` to `true`. ```tsx {(variant, index) => ( )} ``` ### Invalid To make invalid, set `invalid` to `true`. ```tsx {(variant, index) => ( )} ``` ### Change Border Color To customize focus and error border colors, set colors for `focusBorderColor` or `errorBorderColor`. ```tsx ``` ### Customize Icon ```tsx } /> ``` ### Customize Multiple Selection Display ```tsx ( {value} )} /> ``` ### Customize Calendar You can customize Calendar to change the display. ```tsx preview client {({ month }) => `${month.getFullYear()}/${(month.getMonth() + 1).toString().padStart(2, "0")}` } ( {value.getDate()} ), }} /> ``` ### Control ```tsx const [value, setValue] = useState(() => new Date()) return ``` ## Props | Prop | Default | Type | Description | | ---------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `size` | `"md"` | `"lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. | | `variant` | `"outline"` | `"filled" \| "flushed" \| "outline" \| "plain"` | The variant of the component. | | `allowInput` | `true` | `boolean` | If `true`, allows input. | | `allowInputBeyond` | `true` | `boolean` | If `true`, allows input of dates beyond the `minDate` and `maxDate` restrictions. | | `animationScheme` | `"scale"` | `"block-end" \| "block-start" \| "inline-end" \| "inline-start" \| "none" \| "scale" ...` | The animation of the element. | | `autoUpdate` | `true` | `boolean` | If `true`, automatically updates the position of the floating element when necessary. | | `blockScrollOnMount` | `false` | `boolean` | If `true`, scrolling will be disabled on the `body` when the modal opens. | | `calendarProps` | - | `Calendar.RootProps` | The size of the calendar component. | | `clearable` | `true` | `boolean` | If `true`, display the clear icon. | | `clearIcon` | - | `ReactNode` | The icon to be used in the clear button. | | `closeOnBlur` | `true` | `boolean` | If `true`, the popover will close when you blur out it by clicking outside or tabbing out. | | `closeOnChange` | `false` | `boolean \| ((ev: ChangeEvent) => boolean)` | If `true`, the date picker will be closed when the input value changes. | | `closeOnEsc` | `true` | `boolean` | If `true`, the popover will hide on pressing Esc key. | | `closeOnScroll` | `false` | `boolean` | If `true`, the popover will hide on scroll. | | `closeOnSelect` | `true` | `boolean` | If `true`, the list element will be closed when value is selected. | | `contentProps` | - | `DatePickerContentProps` | Props for content element. | | `defaultInputValue` | - | `NonNullable>` | The initial value of the input. | | `defaultMonth` | `new Date()` | `Date \| (() => Date)` | The initial month of the calendar. | | `defaultOpen` | - | `boolean` | If `true`, the element will be initially opened. | | `defaultValue` | - | `NonNullable> \| ToFunction, undefined>>` | The initial value of the calendar. | | `disabled` | `false` | `boolean` | If `true`, disables the calendar. | | `duration` | `0.1` | `MotionLifecycleProps \| number` | The animation duration. | | `elementProps` | - | `InputGroup.ElementProps` | The props for the end element. | | `elements` | - | `{ floating?: HTMLElement \| null \| undefined; reference?: HTMLButtonElement \| null \| undefined; }` | Object containing the reference and floating elements. | | `errorBorderColor` | - | `"-moz-initial" \| "AccentColor" \| "AccentColorText" \| "ActiveBorder" \| "ActiveCaption" \| "ActiveText" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" ...` | The border color when the input is invalid. | | `excludeDate` | - | `(date: Date) => boolean` | Callback function to determine whether the day should be disabled. | | `flip` | `true` | `boolean` | If `true`, the popper will change its placement and flip when it's about to overflow its boundary area. | | `focusBorderColor` | - | `"-moz-initial" \| "AccentColor" \| "AccentColorText" \| "ActiveBorder" \| "ActiveCaption" \| "ActiveText" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" ...` | The border color when the input is focused. | | `focusOnClear` | `true` | `boolean` | If `true`, the input will be focused when the clear icon is clicked. | | `format` | - | `DatePickerFormat` | The format used for conversion. Check the docs to see the format of possible modifiers you can pass. | | `gutter` | `8` | `number` | The distance or margin between the reference and popper. It is used internally to create an `offset` modifier. | | `holidays` | - | `Date[]` | Define holidays. | | `icon` | - | `ReactNode` | The icon to be used in the date picker. | | `iconProps` | - | `DatePickerIconProps` | Props for icon element. | | `inputProps` | - | `HTMLStyledProps<"input">` | The props for the input element. | | `inputValue` | - | `NonNullable>` | The value of the input. | | `invalid` | `false` | `boolean` | If `true`, the field will be invalid. | | `locale` | `"en-US"` | `AnyString \| "ar-AE" \| "bg-BG" \| "cs-CZ" \| "da-DK" \| "de-DE" \| "el-GR" \| "en-GB" \| "en-US" \| "es-ES" \| "et-EE" \| "fi-FI" \| "fr-CA" \| "fr-FR" \| "he-IL" \| "hr-HR" \| "hu-HU" \| ... 18 more ... \| "zh-TW"` | The locale of the calendar. | | `matchWidth` | `false` | `boolean` | If `true`, the popper will match the width of the reference at all times. It's useful for `autocomplete`, `date-picker` and `select` patterns. | | `max` | - | `number` | The maximum selectable value. | | `maxDate` | `new Date(2099, 11, 31)` | `Date` | The maximum possible date. | | `middleware` | - | `(false \| { name: string; options?: any; fn: (state: { x: number; y: number; placement: Placement; platform: { detectOverflow: (state: MiddlewareState, options?: DetectOverflowOptions \| Derivable<...> \| undefined) => Promise<...>; } & Platform; ... 4 more ...; elements: Elements; }) => Promisable<...>; } \| null \| und...` | Array of middleware objects to modify the positioning or provide data for rendering. | | `minDate` | `new Date(1900, 0, 1)` | `Date` | The minimum possible date. | | `month` | - | `Date` | The month of the calendar. | | `multiple` | `false` | `Multiple` | If `true`, the calendar will be multiple. | | `name` | - | `string` | The `name` attribute of the input element. | | `offset` | - | `[number, number]` | The main and cross-axis offset to displace popper element from its reference element. | | `onChange` | - | `(value: MaybeDateValue) => void` | The callback invoked when value state changes. | | `onChangeMonth` | - | `(value: Date) => void` | The callback invoked when month state changes. | | `onClose` | - | `() => void \| Promise` | Callback invoked to close the element. | | `onInputChange` | - | `(value: MaybeInputValue) => void` | The callback invoked when input value state changes. | | `onOpen` | - | `() => void \| Promise` | Callback invoked to open the element. | | `open` | - | `boolean` | If `true`, the element will be opened. | | `openOnChange` | `true` | `boolean \| ((ev: ChangeEvent) => boolean)` | If `true`, the date picker will be opened when the input value changes. | | `openOnClick` | `true` | `boolean` | If `true`, the combobox will be opened when click on the field. | | `openOnEnter` | `true` | `boolean` | If `true`, the combobox will be opened when enter is pressed. | | `openOnFocus` | `true` | `boolean` | If `true`, the date picker will be opened when the input is focused. | | `openOnSpace` | `true` | `boolean` | If `true`, the combobox will be opened when space is pressed. | | `parseDate` | - | `(value: string) => Date \| undefined` | Function that converts the input value to Date type. | | `pattern` | - | `RegExp` | The pattern used to check the input element. | | `placeholder` | - | `string` | The placeholder for date picker. | | `placement` | `"end-start"` | `"center-end-end" \| "center-end-start" \| "center-end" \| "center-start-end" \| "center-start-start" \| "center-start" \| "end-center" \| "end-end" \| "end-start" \| "end" ...` | The placement of the popper relative to its reference. | | `platform` | - | `Platform` | Custom or extended platform object. | | `preventOverflow` | `true` | `boolean` | If `true`, will prevent the popper from being cut off and ensure it's visible within the boundary area. | | `range` | `false` | `Range` | If `true`, enables date range selection. | | `readOnly` | `false` | `boolean` | If `true`, the combobox will be readonly. | | `render` | - | `(props: DatePickerRenderProps) => ReactNode` | The function to render the selected date. | | `required` | `false` | `boolean` | If `true`, the field will be required. | | `rootProps` | - | `InputGroup.RootProps` | Props for root element. | | `selectFocusRef` | - | `RefObject` | The `ref` of the element that should receive focus when selected. | | `selectOnSpace` | `true` | `boolean` | If `true`, the item will be selected when space is pressed. | | `separator` | `","` | `string` | The visual separator between each value. | | `startDayOfWeek` | `"monday"` | `StartDayOfWeek` | Define the start day of the week. | | `strategy` | `"absolute"` | `"absolute" \| "fixed"` | The CSS positioning strategy to use. | | `today` | `true` | `boolean` | If `true`, highlight today. | | `transferFocus` | `true` | `boolean` | If `true`, the focus will be transferred to the popover content when the tab key is pressed. | | `value` | - | `NonNullable>` | The value of the calendar. | | `weekendDays` | `[0, 6]` | `number[]` | Define weekend days. | | `whileElementsMounted` | - | `(reference: HTMLButtonElement, floating: HTMLElement, update: () => void) => () => void` | A callback invoked when both the reference and floating elements are mounted, and cleaned up when either is unmounted. This is useful for setting up event listeners (e.g. pass `autoUpdate`). | ## Accessibility The `DatePicker` follows the [WAI-ARIA - Combobox Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/) for accessibility. If you are not using `Field.Root`, set `aria-label` or `aria-labelledby` to `DatePicker`. ```tsx ``` ```tsx Birthday ``` ### Keyboard Navigation | Key | Description | State | | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | | `Enter` | When the input value is valid, applies it to the selection. Toggles the focused date if focus is in the calendar. Clears the value if focus is on the clear button. | - | | `Backspace` | Clears the last selection. | - | | `Escape` | Closes the calendar. | `closeOnEsc={true}` | | `ArrowUp` | Moves focus to the date above if focus is in the calendar. | - | | `ArrowDown` | Moves focus to the date below if focus is in the calendar. | - | | `ArrowLeft` | Moves focus to the date to the left if focus is in the calendar. If it's the first date, moves to the last date of the previous month. | - | | `ArrowRight` | Moves focus to the date to the right if focus is in the calendar. If it's the last date, moves to the first date of the next month. | - | | `Home` | Moves focus to the first date in the same week if focus is in the calendar. | - | | `End` | Moves focus to the last date in the same week if focus is in the calendar. | - | | `PageUp` | Moves focus to the same date in the previous month if focus is in the calendar. If that date doesn't exist, moves to an enabled date in that month. | - | | `Shift` + `PageUp` | Moves focus to the same date in the previous year if focus is in the calendar. If that date doesn't exist, moves to an enabled date in that month. | - | | `PageDown` | Moves focus to the same date in the next month if focus is in the calendar. If that date doesn't exist, moves to an enabled date in that month. | - | | `Shift` + `PageDown` | Moves focus to the same date in the next year if focus is in the calendar. If that date doesn't exist, moves to an enabled date in that month. | - | | `Space` | Toggles the selection state of the focused date if focus is in the calendar. Clears the value if focus is on the clear button. | - | ### ARIA Roles and Attributes | Element | Roles and Attributes | Usage | | ------------------------------------------------------------------- | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `div.ui-date-picker__field` | `role="combobox"` | Indicates that it is a combobox. | | | `aria-controls` | When the calendar is open, sets the `id` of the associated `div.ui-date-picker__content`. When closed, sets `undefined`. | | | `aria-disabled` | Sets to `"true"` if `disabled` or `readOnly` is set. | | | `aria-describedby` | When `DatePicker` is within `Field.Root` and `Field.Root` has `errorMessage` or `helperMessage`, or `Field.ErrorMessage` or `Field.HelperMessage` is set, sets their `id`. | | | `aria-expanded` | Sets to `"true"` when the calendar is open, and `"false"` when it is closed. | | | `aria-haspopup="dialog"` | Indicates that a dialog exists. | | | `aria-invalid` | Sets to `"true"` if `invalid` is set. | | | `aria-readonly` | Sets to `"true"` if `readOnly` is set. | | | `aria-required` | Sets to `"true"` if `required` is set. | | `div.ui-date-picker__content` | `role="dialog"` | Indicates that it is a dialog. | | | `aria-hidden` | When the calendar is open, sets to `"false"`. When closed, sets to `"true"`. | | `div.ui-date-picker__icon` | `role="button"` | Indicates that it is a button when `clearable` and there is a value. | | | `aria-disabled` | When `clearable` and there is a value, and `disabled` or `readOnly` is set, sets to `"true"`. | | | `aria-label` | When `clearable` and there is a value, sets `"Clear value"`. | | `div.ui-calendar__select--years` | `aria-label` | Sets `"Choose the year"`. | | `div.ui-calendar__select--months` | `aria-label` | Sets `"Choose the month"`. | | `div.ui-calendar__control > div[role="status"][aria-live="polite"]` | `role="status"` | Indicates that it is a status. | | | `aria-live="polite"` | Indicates that it may be updated outside of focus. | | `table.ui-calendar__month` | `role="grid"` | Indicates that it is a grid. | | | `aria-label` | Sets the displayed month and year, like `"February 2026"`. | | | `aria-multiselectable` | Sets `"true"` if multiple selection or range selection is enabled. | | `button.ui-calendar__button--prev` | `aria-label` | Sets `"Go to the previous month"`. | | `button.ui-calendar__button--next` | `aria-label` | Sets `"Go to the next month"`. | | `td.ui-calendar__cell--day` | `aria-label` | Sets the date, like `"Thursday, February 5, 2026"`. If today, sets `"Today, Thursday, February 5, 2026"`. | | | `aria-disabled` | Sets `"true"` if the date is disabled. | | | `aria-selected` | Sets `"true"` if the date is selected. | ## Similar Components - [ColorPicker](https://yamada-ui.com/docs/components/color-picker.md): `ColorPicker` is a component used by the user to select a color or enter an arbitrary color value. - [Select](https://yamada-ui.com/docs/components/select.md): `Select` is a component used for allowing a user to choose values from a list of options. - [Autocomplete](https://yamada-ui.com/docs/components/autocomplete.md): `Autocomplete` is a component used to display suggestions in response to user text input. ## Uses Components & Hooks - [Autocomplete](https://yamada-ui.com/docs/components/autocomplete.md): `Autocomplete` is a component used to display suggestions in response to user text input. - [NativeSelect](https://yamada-ui.com/docs/components/native-select.md): `NativeSelect` is a component used for allowing users to select one value from a list of options. It displays a native dropdown list provided by the browser (user agent). - [Input](https://yamada-ui.com/docs/components/input.md): `Input` is a component used to obtain text input from the user. - [Popover](https://yamada-ui.com/docs/components/popover.md): `Popover` is a component that floats around an element to display information. - [Calendar](https://yamada-ui.com/docs/components/calendar.md): `Calendar` is a component for displaying or selecting dates in a calendar. - [Group](https://yamada-ui.com/docs/components/group.md): `Group` is a component that groups and attaches multiple elements together. - [Icon](https://yamada-ui.com/docs/components/icon.md): `Icon` is a general icon component that can be used in your projects. - [Field](https://yamada-ui.com/docs/components/field.md): `Field` is a component used to group form elements with label, helper message, error message, etc. - [Format](https://yamada-ui.com/docs/components/format.md): `Format` is used to format dates, numbers, and bytes according to a specific locale. ## Used By Components & Hooks - [ColorPicker](https://yamada-ui.com/docs/components/color-picker.md): `ColorPicker` is a component used by the user to select a color or enter an arbitrary color value.