Components / Inputs
DateRangePicker
Pick a start and end date (MUI X Pro's DateRangePicker). ref points at the field's button.
import { DateRangePicker } from "@stylhero/ui";
Example
Code
import { useState } from "react";
import { DateRangePicker, type DateRange } from "@stylhero/ui";
function DateRangePickerExample() {
const [range, setRange] = useState<DateRange>([null, null]);
return <DateRangePicker label="Trip" value={range} onValueChange={setRange} />;
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
className |
string |
- | |
clearable |
boolean |
- | Shows an X to clear the value. |
defaultValue |
DateRange |
[null, null] |
|
disabled |
boolean |
- | |
error |
ReactNode |
- | |
format |
Intl.DateTimeFormatOptions |
{ dateStyle: "medium" } |
Intl date format for the field. |
hint |
ReactNode |
- | Help text under the field. Replaced by error when set. |
id |
string |
- | |
isDateDisabled |
(d: Date) => boolean |
- | Return true to block a day (e.g. closed on Sundays). |
label |
ReactNode |
- | |
locale |
string |
- | BCP 47 locale for month and weekday names, e.g. "es-MX". Defaults to the browser's. |
max |
Date |
- | |
min |
Date |
- | |
name |
string |
- | Submits the value as YYYY-MM-DD (range: two fields, name[0] and name[1]). |
onBlur |
FocusEventHandler<HTMLElement> |
- | Runs when the field loses focus (react-hook-form's field.onBlur). |
onValueChange |
(r: DateRange) => void |
- | |
placeholder |
string |
"Pick dates" |
|
presets |
Array<{ label: string; range: [Date, Date] }> |
- | Quick picks shown beside the calendar, e.g. [{ label: "Last 7 days", range: [...] }]. |
value |
DateRange |
- | |
weekStartsOn |
0 | 1 |
- | 0 = Sunday, 1 = Monday. |
Takes a ref.
Types
type DateRange = [Date | null, Date | null];
Keyboard
| Key | Does |
|---|---|
| Enter / Space | Opens the calendar on the field's button |
| Arrow keys | Move one day (left/right) or one week (up/down). Disabled days are skipped |
| Home / End | First / last day of the week |
| PageUp / PageDown | Previous / next month; with Shift, previous / next year |
| Enter / Space | Picks the focused day |
| Esc | Closes the calendar and returns focus to the field |
Accessibility
- Pick the start, then the end. The field announces both dates.
- The label, hint and error are linked to the control (
aria-describedby), anderrorsetsaria-invalid.
Generated from src/components/DatePicker.tsx. Something wrong or missing? Open an issue.