No date yet
presentationnoPastweekdaysOnlydropdowndisabledimport { useState } from "react"
import { DatePicker } from "@/components/ui/date-picker"
export function DueDate() {
const [due, setDue] = useState<Date | null>(null)
return (
<DatePicker
aria-label="Due date"
label="Due date"
min={new Date()}
value={due}
onValueChange={setDue}
/>
)
}Usage
import { useState } from "react"
import { DatePicker } from "@/components/ui/date-picker"
export function DueDate() {
const [due, setDue] = useState<Date | null>(null)
return <DatePicker aria-label="Due date" value={due} onValueChange={setDue} min={new Date()} />
}Examples
No date yet
import { useState } from 'react';
import { DatePicker } from '@/components/ui/date-picker';
export function Example() {
const [due, setDue] = useState<Date | null>(null);
return <DatePicker aria-label="Due date" label="Due date" value={due} onValueChange={setDue} min={new Date()} />;
}import { DatePicker } from '@/components/ui/date-picker';
export function Example() {
return (
<DatePicker
aria-label="Delivery day"
label="Delivery day"
min={new Date()}
isDateDisabled={(d) => d.getDay() === 0 || d.getDay() === 6}
placeholder="mon or 24 nov"
/>
);
}Notes
Server rendering
Pass today when the page renders on a server, so the server and the browser agree on which day it is.
Typing first
The line under the field shows the day it reads before anything commits, and how far away it is. Text that isn't a date, or a day that can't be picked, says why there and marks the field invalid; it is never thrown away. So does a value set from outside that can't be picked. A two-digit year lands inside min and max when it can, so 75 in a birth date field is 1975. Esc puts back the last committed day.
On phones
Below 768px the calendar opens in a drawer with its own field, preset chips and a confirm button. Nothing commits until that button is pressed, so swiping the drawer away leaves the value as it was.
API
details.cancel() refuses it.dropdown gives the calendar month and year selects, for days years away such as a birth date.YYYY-MM-DD.locale also sets how 3/12 is read.Agent
Inside an AgentProvider, it appears in agent.snapshot() as date.
Reads
labelThe field's aria-label.
valueYYYY-MM-DD, or absent when empty.
invalid, errorsSet while the field holds text that doesn't read, with the message the person sees.
disabledTrue when the picker is blocked.
Actions
setValue("2026-12-24")Commits the day. Phrases work too: next fri, in 2 weeks, 21 nov.
clear()Empties the value.
An agent's change runs through onValueChange like anyone's. isAgentChange(details) is true for it; details.cancel() refuses it. Days the field would refuse are refused with the same words.
await agent.act({
steps: [{ ref: "Due date", action: "setValue", args: ["next fri"] }],
})Accessibility
- The line under the field is a live region tied to the field by aria-describedby, so the reading is announced as you type.
- An unreadable entry sets aria-invalid and the field's validation message.
- The calendar button's name includes the committed day.
- Picking a day returns focus to the field.