# Date Input URL: https://ark-ui.com/docs/components/date-input Source: https://raw.githubusercontent.com/chakra-ui/ark/refs/heads/main/website/src/content/pages/components/date-input.mdx A segment-based date input that allows users to enter dates by navigating individual date parts. --- ## Anatomy ```tsx ``` ## Examples **Example: basic** #### React ```tsx import { DateInput } from '@ark-ui/react/date-input' import styles from 'styles/date-input.module.css' export const Basic = () => ( Date {(segment) => } ) ``` #### Solid ```tsx import { DateInput } from '@ark-ui/solid/date-input' import styles from 'styles/date-input.module.css' export const Basic = () => ( Date {(segment) => } ) ``` #### Vue ```vue ``` #### Svelte ```svelte Date {#snippet render(segment)} {/snippet} ``` ### Default Value Use the `defaultValue` prop with `parseDate` to set the initial date value. **Example: default-value** #### React ```tsx import { DateInput } from '@ark-ui/react/date-input' import { parseDate } from '@internationalized/date' import styles from 'styles/date-input.module.css' export const DefaultValue = () => ( Date {(segment) => } ) ``` #### Solid ```tsx import { DateInput } from '@ark-ui/solid/date-input' import { parseDate } from '@internationalized/date' import styles from 'styles/date-input.module.css' export const DefaultValue = () => ( Date {(segment) => } ) ``` #### Vue ```vue ``` #### Svelte ```svelte Date {#snippet render(segment)} {/snippet} ``` ### Controlled Use the `value` and `onValueChange` props to control the date input's value programmatically. **Example: controlled** #### React ```tsx import { DateInput } from '@ark-ui/react/date-input' import { parseDate, type DateValue } from '@internationalized/date' import { useState } from 'react' import styles from 'styles/date-input.module.css' export const Controlled = () => { const [value, setValue] = useState([parseDate('2024-06-15')]) return ( setValue(details.value)}> Date {(segment) => } ) } ``` #### Solid ```tsx import { DateInput } from '@ark-ui/solid/date-input' import { parseDate, type DateValue } from '@internationalized/date' import { createSignal } from 'solid-js' import styles from 'styles/date-input.module.css' export const Controlled = () => { const [value, setValue] = createSignal([parseDate('2024-06-15')]) return ( setValue(e.value)}> Date {(segment) => } ) } ``` #### Vue ```vue ``` #### Svelte ```svelte Date {#snippet render(segment)} {/snippet} ``` ### Root Provider An alternative way to control the date input is to use the `RootProvider` component and the `useDateInput` hook. This way you can access the state and methods from outside the component. **Example: root-provider** #### React ```tsx import { DateInput, useDateInput } from '@ark-ui/react/date-input' import styles from 'styles/date-input.module.css' export const RootProvider = () => { const dateInput = useDateInput() return ( {dateInput.valueAsString.length > 0 ? dateInput.valueAsString : 'N/A'} Date {(segment) => } ) } ``` #### Solid ```tsx import { DateInput, useDateInput } from '@ark-ui/solid/date-input' import styles from 'styles/date-input.module.css' export const RootProvider = () => { const dateInput = useDateInput() return ( {dateInput().valueAsString.length > 0 ? dateInput().valueAsString : 'N/A'} Date {(segment) => } ) } ``` #### Vue ```vue ``` #### Svelte ```svelte {dateInput().valueAsString.length > 0 ? dateInput().valueAsString : 'N/A'} Date {#snippet render(segment)} {/snippet} ``` ### Granularity Use the `granularity` prop to control which date fields are displayed. Supported values are `day`, `hour`, `minute`, and `second`. **Example: granularity** #### React ```tsx import { DateInput } from '@ark-ui/react/date-input' import styles from 'styles/date-input.module.css' export const Granularity = () => ( Date & Time {(segment) => } ) ``` #### Solid ```tsx import { DateInput } from '@ark-ui/solid/date-input' import styles from 'styles/date-input.module.css' export const Granularity = () => ( Date & Time {(segment) => } ) ``` #### Vue ```vue ``` #### Svelte ```svelte Date & Time {#snippet render(segment)} {/snippet} ``` ### Time Only To create a time-only input, set `granularity` to `minute` (or `second`) and provide a `formatter` that only includes time fields. Use the `hourCycle` prop to switch between 12 and 24 hour formats. **Example: time-only** #### React ```tsx import { DateInput } from '@ark-ui/react/date-input' import { DateFormatter } from '@internationalized/date' import styles from 'styles/date-input.module.css' const timeFormatter = new DateFormatter('en-US', { hour: '2-digit', minute: '2-digit', hourCycle: 'h23', }) export const TimeOnly = () => ( Time {(segment) => } ) ``` #### Solid ```tsx import { DateInput } from '@ark-ui/solid/date-input' import { DateFormatter } from '@internationalized/date' import styles from 'styles/date-input.module.css' const timeFormatter = new DateFormatter('en-US', { hour: '2-digit', minute: '2-digit', hourCycle: 'h23', }) export const TimeOnly = () => ( Time {(segment) => } ) ``` #### Vue ```vue ``` #### Svelte ```svelte Time {#snippet render(segment)} {/snippet} ``` ### Range To create a date input that allows a range selection, set the `selectionMode` prop to `range` and render two `SegmentGroup` components with `index` props set to `0` and `1`. **Example: range** #### React ```tsx import { DateInput } from '@ark-ui/react/date-input' import styles from 'styles/date-input.module.css' export const Range = () => ( Date Range {(segment) => } {(segment) => } ) ``` #### Solid ```tsx import { DateInput } from '@ark-ui/solid/date-input' import styles from 'styles/date-input.module.css' export const Range = () => ( Date Range {(segment) => } {(segment) => } ) ``` #### Vue ```vue ``` #### Svelte ```svelte Date Range {#snippet render(segment)} {/snippet} {#snippet render(segment)} {/snippet} ``` ### Min and Max Use the `min` and `max` props with `parseDate` to restrict the selectable date range. Dates outside this range will be marked as invalid. **Example: min-max** #### React ```tsx import { DateInput } from '@ark-ui/react/date-input' import { parseDate } from '@internationalized/date' import styles from 'styles/date-input.module.css' export const MinMax = () => ( Date (2024 only) {(segment) => } ) ``` #### Solid ```tsx import { DateInput } from '@ark-ui/solid/date-input' import { parseDate } from '@internationalized/date' import styles from 'styles/date-input.module.css' export const MinMax = () => ( Date (2024 only) {(segment) => } ) ``` #### Vue ```vue ``` #### Svelte ```svelte Date (2024 only) {#snippet render(segment)} {/snippet} ``` ### Disabled Use the `disabled` prop to prevent user interaction with the date input. **Example: disabled** #### React ```tsx import { DateInput } from '@ark-ui/react/date-input' import { parseDate } from '@internationalized/date' import styles from 'styles/date-input.module.css' export const Disabled = () => ( Date {(segment) => } ) ``` #### Solid ```tsx import { DateInput } from '@ark-ui/solid/date-input' import { parseDate } from '@internationalized/date' import styles from 'styles/date-input.module.css' export const Disabled = () => ( Date {(segment) => } ) ``` #### Vue ```vue ``` #### Svelte ```svelte Date {#snippet render(segment)} {/snippet} ``` ### Read Only Use the `readOnly` prop to make the date input non-editable while still being focusable. **Example: read-only** #### React ```tsx import { DateInput } from '@ark-ui/react/date-input' import { parseDate } from '@internationalized/date' import styles from 'styles/date-input.module.css' export const ReadOnly = () => ( Date {(segment) => } ) ``` #### Solid ```tsx import { DateInput } from '@ark-ui/solid/date-input' import { parseDate } from '@internationalized/date' import styles from 'styles/date-input.module.css' export const ReadOnly = () => ( Date {(segment) => } ) ``` #### Vue ```vue ``` #### Svelte ```svelte Date {#snippet render(segment)} {/snippet} ``` ### Invalid Use the `invalid` prop to indicate an error state on the date input. **Example: invalid** #### React ```tsx import { DateInput } from '@ark-ui/react/date-input' import styles from 'styles/date-input.module.css' export const Invalid = () => ( Date {(segment) => } ) ``` #### Solid ```tsx import { DateInput } from '@ark-ui/solid/date-input' import styles from 'styles/date-input.module.css' export const Invalid = () => ( Date {(segment) => } ) ``` #### Vue ```vue ``` #### Svelte ```svelte Date {#snippet render(segment)} {/snippet} ``` ### Leading Zeros Use the `shouldForceLeadingZeros` prop to toggle whether numeric segments are padded with a leading zero. **Example: leading-zeros** #### React ```tsx import { DateInput } from '@ark-ui/react/date-input' import { parseDate } from '@internationalized/date' import { useState } from 'react' import styles from 'styles/date-input.module.css' export const LeadingZeros = () => { const [shouldForceLeadingZeros, setShouldForceLeadingZeros] = useState(true) return (
Date {(segment) => }
) } ``` #### Solid ```tsx import { DateInput } from '@ark-ui/solid/date-input' import { parseDate } from '@internationalized/date' import { createSignal } from 'solid-js' import styles from 'styles/date-input.module.css' export const LeadingZeros = () => { const [shouldForceLeadingZeros, setShouldForceLeadingZeros] = createSignal(true) return (
Date {(segment) => }
) } ``` #### Vue ```vue ``` #### Svelte ```svelte
Date {#snippet render(segment)} {/snippet}
``` ### Localized Use the `locale` prop to set the language and regional formatting of the date segments. **Example: localized** #### React ```tsx import { DateInput } from '@ark-ui/react/date-input' import { LocaleProvider } from '@ark-ui/react/locale' import styles from 'styles/date-input.module.css' export const Localized = () => ( Date et heure {(segment) => } ) ``` #### Solid ```tsx import { DateInput } from '@ark-ui/solid/date-input' import { LocaleProvider } from '@ark-ui/solid/locale' import styles from 'styles/date-input.module.css' export const Localized = () => ( Date et heure {(segment) => } ) ``` #### Vue ```vue ``` #### Svelte ```svelte Date et heure {#snippet render(segment)} {/snippet} ``` ### RTL Set the `dir` prop to `rtl` for right-to-left language support. **Example: rtl** #### React ```tsx import { DateInput } from '@ark-ui/react/date-input' import { LocaleProvider } from '@ark-ui/react/locale' import styles from 'styles/date-input.module.css' export const RTL = () => ( التاريخ {(segment) => } ) ``` #### Solid ```tsx import { DateInput } from '@ark-ui/solid/date-input' import { LocaleProvider } from '@ark-ui/solid/locale' import styles from 'styles/date-input.module.css' export const RTL = () => ( التاريخ {(segment) => } ) ``` #### Vue ```vue ``` #### Svelte ```svelte التاريخ {#snippet render(segment)} {/snippet} ``` ### With Clear Button Use `useDateInput` via `RootProvider` to access the `clearValue` method and render a clear button alongside the input. **Example: with-clear-button** #### React ```tsx import { DateInput, useDateInput } from '@ark-ui/react/date-input' import { XIcon } from 'lucide-react' import button from 'styles/button.module.css' import styles from 'styles/date-input.module.css' export const WithClearButton = () => { const dateInput = useDateInput() return ( Date {(segment) => } ) } ``` #### Solid ```tsx import { DateInput, useDateInput } from '@ark-ui/solid/date-input' import { XIcon } from 'lucide-solid' import button from 'styles/button.module.css' import styles from 'styles/date-input.module.css' export const WithClearButton = () => { const dateInput = useDateInput() return ( Date {(segment) => } ) } ``` #### Vue ```vue ``` #### Svelte ```svelte Date {#snippet render(segment)} {/snippet} ``` ### With Date Picker Combine `DateInput` with `DatePicker` by syncing their values using `onValueChange` to provide both typed and calendar-based date selection. **Example: with-date-picker** #### React ```tsx import { DateInput, useDateInput } from '@ark-ui/react/date-input' import { DatePicker, useDatePicker } from '@ark-ui/react/date-picker' import { Portal } from '@ark-ui/react/portal' import { CalendarIcon, ChevronLeftIcon, ChevronRightIcon } from 'lucide-react' import styles from 'styles/date-input.module.css' import datePickerStyles from 'styles/date-picker.module.css' export const WithDatePicker = () => { const datePicker = useDatePicker() const dateInput = useDateInput({ value: datePicker.value, onValueChange(details) { datePicker.setValue(details.value) }, }) return ( Date {(dateInput) => dateInput .getSegments() .map((segment, index) => ( )) } {(datePicker) => ( <> {datePicker.weekDays.map((weekDay, id) => ( {weekDay.short} ))} {datePicker.weeks.map((week, id) => ( {week.map((day, id) => ( {day.day} ))} ))} )} {(datePicker) => ( <> {datePicker.getMonthsGrid({ columns: 4, format: 'short' }).map((months, id) => ( {months.map((month, id) => ( {month.label} ))} ))} )} {(datePicker) => ( <> {datePicker.getYearsGrid({ columns: 4 }).map((years, id) => ( {years.map((year, id) => ( {year.label} ))} ))} )} ) } ``` #### Solid ```tsx import { DateInput, useDateInput } from '@ark-ui/solid/date-input' import { DatePicker, useDatePicker } from '@ark-ui/solid/date-picker' import { CalendarIcon, ChevronLeftIcon, ChevronRightIcon } from 'lucide-solid' import { Index } from 'solid-js' import { Portal } from 'solid-js/web' import styles from 'styles/date-input.module.css' import datePickerStyles from 'styles/date-picker.module.css' export const WithDatePicker = () => { const datePicker = useDatePicker() const dateInput = useDateInput(() => ({ value: datePicker().value, onValueChange(details) { datePicker().setValue(details.value) }, })) return ( Date {(segment) => } {(datePicker) => ( <> {(weekDay) => ( {weekDay().short} )} {(week) => ( {(day) => ( {day().day} )} )} )} {(datePicker) => ( <> {(months) => ( {(month) => ( {month().label} )} )} )} {(datePicker) => ( <> {(years) => ( {(year) => ( {year().label} )} )} )} ) } ``` #### Vue ```vue ``` #### Svelte ```svelte Date {#snippet render(segment)} {/snippet} {#snippet render(datePicker)} {#each datePicker().weekDays as weekDay} {weekDay.short} {/each} {#each datePicker().weeks as week} {#each week as day} {day.day} {/each} {/each} {/snippet} {#snippet render(datePicker)} {#each datePicker().getMonthsGrid({ columns: 4, format: 'short' }) as months} {#each months as month} {month.label} {/each} {/each} {/snippet} {#snippet render(datePicker)} {#each datePicker().getYearsGrid({ columns: 4 }) as years} {#each years as year} {year.label} {/each} {/each} {/snippet} ``` ## API Reference ### Props ### Context **API:** | Property | Type | Description | |----------|------|-------------| | `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. | ## Accessibility Complies with the [Spinbutton WAI-ARIA design pattern](https://www.w3.org/WAI/ARIA/apg/patterns/spinbutton/).