No range yet
presentationpresetsnoFuturedisabledimport { useState } from "react"
import { type DateRange } from "@/components/ui/calendar"
import { DateRangePicker } from "@/components/ui/date-range-picker"
export function Period() {
const [range, setRange] = useState<DateRange>({ from: null, to: null })
return (
<DateRangePicker
aria-label="Period"
max={new Date()}
value={range}
onValueChange={setRange}
/>
)
}Usage
import { useState } from "react"
import { type DateRange } from "@/components/ui/calendar"
import { DateRangePicker } from "@/components/ui/date-range-picker"
export function Period() {
const [range, setRange] = useState<DateRange>({ from: null, to: null })
return <DateRangePicker aria-label="Period" value={range} onValueChange={setRange} max={new Date()} />
}Examples
import { useState } from 'react';
import { addDays, startOfDay, type DateRange } from '@/components/ui/calendar';
import { DateRangePicker } from '@/components/ui/date-range-picker';
export function Example() {
const today = startOfDay(new Date());
const [range, setRange] = useState<DateRange>({ from: addDays(today, -6), to: today });
return <DateRangePicker aria-label="Period" value={range} onValueChange={setRange} max={today} />;
}import { addDays, startOfDay } from '@/components/ui/calendar';
import { DateRangePicker } from '@/components/ui/date-range-picker';
export function Example() {
const today = startOfDay(new Date());
const saturday = addDays(today, (6 - today.getDay() + 7) % 7);
return (
<DateRangePicker
aria-label="Stay"
label="Stay"
placeholder="Check in, check out"
min={today}
presets={[
{ label: "This weekend", value: { from: saturday, to: addDays(saturday, 1) } },
{ label: "Next 7 nights", value: { from: today, to: addDays(today, 7) } },
]}
/>
);
}Notes
Server rendering
Pass today when the page renders on a server, so the server and the browser agree on which day it is.
Presets and Custom
Picking on the calendar switches the preset to Custom. A preset range names itself on the trigger with its dates beside it; a custom one shows its dates. Pressing Custom clears the range to start again.
Apply and Cancel
The range is a draft until Apply, which stays off until the range has an end. Cancel, Esc and a click outside all leave the applied range as it was. While you pick the end, the footer counts the days to the one under the pointer. A range set from outside that runs across a blocked day marks the trigger invalid, and the footer says which day.
API
{ from, to }.details.cancel() refuses it.pastPresets(today): today, yesterday, the last 7 and 30 days, this month and last month. Pass [] for none. Presets outside the bounds are dropped; one that runs across a blocked day shows disabled, with the reason.details.reason is range-blocked when a press past a blocked day restarted it.YYYY-MM-DD/YYYY-MM-DD.Agent
Inside an AgentProvider, it appears in agent.snapshot() as date.
Reads
labelThe trigger's aria-label.
value[from, to] as YYYY-MM-DD, or absent when empty.
itemsThe preset labels, any of which setValue accepts.
multipleAlways true: the value is a list.
invalidTrue when the range set from outside runs across a blocked day.
Actions
setValue("Last 7 days")Applies a preset by its label.
setValue(["2026-11-02", "2026-11-08"])Applies two dates. "2 nov to 8 nov" works too.
clear()Empties the range.
An agent's change runs through onValueChange like anyone's. isAgentChange(details) is true for it; details.cancel() refuses it. A range that ends before it starts, falls outside min and max, or runs across a blocked day is refused with the reason.
await agent.act({
steps: [{ ref: "Period", action: "setValue", args: ["Last 30 days"] }],
})Accessibility
- The trigger's name holds the range, after its label when one is given.
- Presets are toggle buttons; the active one has aria-pressed.
- The footer is a live region, so the range and day count are announced as they change.