Get Started
Components
- Alert
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Checkbox Group
- ComboBox
- Command
- Data Table
- Date Field
- Date Picker
- Date Range Picker
- Dialog
- Disclosure
- Disclosure Group
- Drawer
- Empty
- Field
- File Trigger
- Form
- Grid List
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- ListBox
- Menu
- Number Field
- Pagination
- Popover
- Progress Bar
- Radio Group
- Range Calendar
- Resizable
- Search Field
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Tag Group
- Text Field
- Textarea
- Time Field
- Toast
- Toggle Button
- Toggle Button Group
- Tooltip
- Tree
- Typography
AI Elements
Event date
mm/dd/yyyy
Select a date for your event.import { DateField } from "@/components/ui/date-field"
export function DateFieldDemo() {
return (
<DateField label="Event date" description="Select a date for your event." />
)
}
Installation
CLI
Manual
pnpmnpmyarnbunpnpm dlx shadcn@latest add date-field
Usage
import { DateField } from "@/components/ui/date-field"<DateField
label="Event date"
description="Select a date for your event."
/>About
The DateField component is built on top of React Aria Components and uses the @internationalized/date library for date manipulation.
Examples
Default
Event date
mm/dd/yyyy
Select a date for your event.import { DateField } from "@/components/ui/date-field"
export function DateFieldDemo() {
return (
<DateField label="Event date" description="Select a date for your event." />
)
}
<DateField
label="Event date"
description="Select a date for your event."
/>Disabled
Event date
mm/dd/yyyy
This field is disabled.import { DateField } from "@/components/ui/date-field"
export function DateFieldDisabled() {
return (
<DateField
label="Event date"
description="This field is disabled."
isDisabled
/>
)
}
<DateField
label="Event date"
description="This field is disabled."
isDisabled
/>Validation
Birth date
mm/dd/yyyy
Enter your birth date."use client"
import { DateField } from "@/components/ui/date-field"
export function DateFieldValidation() {
return (
<DateField
label="Birth date"
description="Enter your birth date."
isRequired
errorMessage="Please enter a valid date."
/>
)
}
<DateField
label="Birth date"
description="Enter your birth date."
isRequired
errorMessage="Please enter a valid date."
/>Controlled
Appointment date
1/15/2024
Select your appointment date.Selected date: 2024-01-15
"use client"
import { useState } from "react"
import { parseDate } from "@internationalized/date"
import { DateField } from "@/components/ui/date-field"
export function DateFieldControlled() {
const [value, setValue] = useState(parseDate("2024-01-15"))
return (
<div className="space-y-4">
<DateField
label="Appointment date"
description="Select your appointment date."
value={value}
onChange={setValue}
/>
<p className="text-muted-foreground text-sm">
Selected date: {value ? value.toString() : "None"}
</p>
</div>
)
}
"use client"
import { useState } from "react"
import { parseDate } from "@internationalized/date"
import { DateField } from "@/components/ui/date-field"
export default function DateFieldControlled() {
const [value, setValue] = useState(parseDate("2024-01-15"))
return (
<div className="space-y-4">
<DateField
label="Appointment date"
description="Select your appointment date."
value={value}
onChange={setValue}
/>
<p className="text-sm text-muted-foreground">
Selected date: {value ? value.toString() : "None"}
</p>
</div>
)
}Min and Max Values
Meeting date
mm/dd/yyyy
Select a date within the next 7 days."use client"
import { getLocalTimeZone, today } from "@internationalized/date"
import { DateField } from "@/components/ui/date-field"
export function DateFieldMinMax() {
const now = today(getLocalTimeZone())
return (
<DateField
label="Meeting date"
description="Select a date within the next 7 days."
minValue={now}
maxValue={now.add({ days: 7 })}
/>
)
}
"use client"
import { today, getLocalTimeZone } from "@internationalized/date"
import { DateField } from "@/components/ui/date-field"
export default function DateFieldMinMax() {
const now = today(getLocalTimeZone())
return (
<DateField
label="Meeting date"
description="Select a date within the next 7 days."
minValue={now}
maxValue={now.add({ days: 7 })}
/>
)
}Granularity
Date only
mm/dd/yyyy
Year, month, and day.Month and year
mm/yyyy
Month and year only.import { DateField } from "@/components/ui/date-field"
export function DateFieldGranularity() {
return (
<div className="space-y-4">
<DateField
label="Date only"
description="Year, month, and day."
granularity="day"
/>
<DateField
label="Month and year"
description="Month and year only."
granularity="month"
/>
</div>
)
}
<div className="space-y-4">
<DateField
label="Date only"
description="Year, month, and day."
granularity="day"
/>
<DateField
label="Month and year"
description="Month and year only."
granularity="month"
/>
</div>API Reference
DateField
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | - | Label text for the date field |
description | string | - | Help text displayed below the input |
errorMessage | string | ((validation: ValidationResult) => string) | - | Error message for validation |
value | DateValue | - | The current value (controlled) |
defaultValue | DateValue | - | The default value (uncontrolled) |
onChange | (value: DateValue) => void | - | Handler called when the value changes |
minValue | DateValue | - | The minimum allowed date |
maxValue | DateValue | - | The maximum allowed date |
granularity | "day" | "hour" | "minute" | "second" | "day" | Determines the smallest unit editable |
isDisabled | boolean | false | Whether the date field is disabled |
isReadOnly | boolean | false | Whether the date field is read-only |
isRequired | boolean | false | Whether the date field is required |
placeholderValue | DateValue | - | A placeholder date that controls the default values of segments |
See the React Aria DateField documentation for more props and detailed information.
Internationalization
The DateField component automatically formats dates based on the user's locale. The @internationalized/date library handles calendar systems and localization.
import { parseDate } from "@internationalized/date"
// ISO 8601 format
const date = parseDate("2024-12-25")Calendar Systems
The date field supports multiple calendar systems through the @internationalized/date library:
- Gregorian
- Buddhist
- Hebrew
- Indian
- Islamic (Hijri)
- Japanese
- Persian
- Taiwan
See the @internationalized/date documentation for more information.
Related Components
- Calendar - For visual date selection
- Date Picker - Combines a date field with a calendar popover
- Field - For composing accessible form fields