Range calendar
A month grid for picking a start and an end date.
SourceStyles source@monoline/react 0.4.0Markdown for AI toolsstable
- Built on native elements
- role="grid" with column headers; one day is in the tab order (roving tabindex).
- Enter or Space on a day sets the start, then the end; Escape while picking clears the start.
- Arrow keys move by day and week, Home/End to the start and end of the week, PageUp/PageDown by month; arrows are mirrored in right-to-left.
- Styles in one file:
calendar.css
Import
import '@monoline/css';
import {RangeCalendar} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add range-calendar
Usage
import {RangeCalendar} from '@monoline/react';
<RangeCalendar weekStartsOn={1} />
Examples
Basic
With limits and blocked days
Weekends are blocked; only the next 60 days can be chosen.
Props
RangeCalendarProps
| Prop | Type | Default | Description |
|---|---|---|---|
value | DateRange | – | The selected range when controlled. Pair with `onValueChange`. |
defaultValue | DateRange | EMPTY | The initially selected range when uncontrolled. Default empty. |
onValueChange | ((range: DateRange) => void) | – | Called after every pick. The first pick gives `{start, end: null}`; the second completes the range. |
weekStartsOn | 0 | 1 | 0 | First day of the week: 0 = Sunday, 1 = Monday. Default 0. |
min | Date | – | Earliest selectable date; earlier days are disabled. |
max | Date | – | Latest selectable date; later days are disabled. |
isDateDisabled | ((date: Date) => boolean) | – | Return true for a day that cannot be picked, such as a holiday. |
locale | string | – | BCP 47 locale for month and day names. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
| Attribute | Stylesheet |
|---|---|
[aria-pressed="true"] | calendar.css |
[data-outside] | calendar.css |
[data-today] | calendar.css |
[aria-pressed="true"] | range-calendar.css |
[data-in-range] | range-calendar.css |
[data-preview] | range-calendar.css |
[data-range-start] | range-calendar.css |
CSS classes
| Class | Stylesheet |
|---|---|
.calendar | calendar.css |
.calendar-day | calendar.css |
.calendar-grid | calendar.css |
.calendar-head | calendar.css |
.calendar-nav | calendar.css |
.calendar-title | calendar.css |
.calendar-day | range-calendar.css |
.range-calendar | range-calendar.css |
.range-cell | range-calendar.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.calendar {
border-color: var(--accent);
}
.calendar[aria-pressed="true"] {
background: var(--wash);
}
Accessibility
- role="grid" with column headers; one day is in the tab order (roving tabindex).
- Enter or Space on a day sets the start, then the end; Escape while picking clears the start.
- Arrow keys move by day and week, Home/End to the start and end of the week, PageUp/PageDown by month; arrows are mirrored in right-to-left.
- The days between start and focus are previewed while picking, by hover and by keyboard.
- Each day button has a full date name; start and end have aria-pressed; a status region announces the chosen range.
- Disabled days (min, max, isDateDisabled) are real disabled buttons.
Keyboard
| Keys | Action |
|---|---|
| Enter / Space | On a day sets the start, then the end |
| Escape | While picking clears the start |
| Arrow keys | Move by day and week |
| Home / End | To the start and end of the week |
| PageUp / PageDown | By month |