Loading component…
Loading component…
Presets and two calendars with a hover preview, comparison with the previous period or year, full keyboard control
To reuse this local React demo, copy all files from the Code tab into the same folder, then import DateRangePicker from ./date-range-picker.
import { DateRangePicker, type DateRange } from "@/components/ui/date-range-picker";
export function ReportFilter() {
return (
<DateRangePicker
onChange={(range, compare) => {
loadReport(range.start, range.end);
if (compare) loadComparison(compare.start, compare.end);
}}
/>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| value | { start: Date; end: Date } | Controlled range | |
| defaultValue | { start: Date; end: Date } | last 30 days | Starting range when uncontrolled |
| onChange | (range, compare, mode) => void | Called on Apply with the range, the comparison range (or null) and the compare mode | |
| presets | { id, label, range: (today) => DateRange }[] | Today … Year to date | The list on the left (chips on phones) |
| compare | boolean | true | Show "Compare: Off / Previous period / Previous year" |
| defaultCompare | "off" \| "previous" \| "year" | "previous" | Comparison selected at the start |
| weekStartsOn | 0 \| 1 | 1 | 0 = Sunday, 1 = Monday |
| min / max | Date | max: today | Days outside can't be picked |
| defaultOpen | boolean | false | Open the panel right away |
| today | Date | now | Reference day for the presets – handy for tests and screenshots |
| className | string | Extra class on the root |
Below 600px the presets turn into a scrolling row of chips and only the month the range ends in is shown; the footer stacks
The panel is as wide as the screen allows (up to 652px); set --ui-drp-panel-width, e.g. to 100%, to match your layout
Bigger day cells and buttons on touch screens
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"