# 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
Date
```
#### 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
Date
```
#### 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
Date
```
#### 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 (
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 (
Date
{(segment) => }
)
}
```
#### Vue
```vue
Date
```
#### Svelte
```svelte
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
Date & Time
```
#### 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
Time
```
#### 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
Date Range→
```
#### 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
Date (2024 only)
```
#### 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
Date
```
#### 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
Date
```
#### 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
Date
```
#### 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 (