Calendar
A month grid for picking one date.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- Built on native elements
- role="grid" with column headers; one day is in the tab order (roving tabindex).
- Arrow keys move by day and week, Home/End to the start and end of the week, PageUp/PageDown by month.
- Each day button has a full date name; the selected day has aria-pressed and today has aria-current="date".
- Styles in one file:
calendar.css
Import
import '@monoline/css';
import {Calendar} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add calendar
Usage
import {useState} from 'react';
import {Calendar, type Demo} from '@monoline/react';
function Demo() {
const [d, setD] = useState<Date | null>(null);
return <div style={{display: 'grid', gap: 'var(--s3)', justifyItems: 'start'}}><Calendar value={d} onValueChange={setD} weekStartsOn={1} /><p className="muted small" role="status">{d ? d.toDateString() : 'No date picked'}</p></div>;
}
<Demo />
Examples
Pick a date
Props
CalendarProps
| Prop | Type | Default | Description |
|---|---|---|---|
value | Date | null | – | The selected date when controlled; `null` means none. Pair with `onValueChange`. |
defaultValue | Date | null | null | The initially selected date when uncontrolled. Default none. |
onValueChange | ((date: Date | null) => void) | – | Called with the date the user picks, or `null` when the user presses "Clear date" (only with `clearable`). |
clearable | boolean | false | Adds a "Clear date" button under the grid that resets the value to `null`. Default false. |
weekStartsOn | 0 | 1 | 0 | First day of the week: 0 = Sunday, 1 = Monday. |
min | Date | – | Earliest selectable date; earlier days are disabled. |
max | Date | – | Latest selectable date; later days are disabled. |
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 |
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 |
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).
- Arrow keys move by day and week, Home/End to the start and end of the week, PageUp/PageDown by month.
- Each day button has a full date name; the selected day has aria-pressed and today has aria-current="date".
- With `clearable`, a "Clear date" button resets the value; it is disabled while no date is chosen.
Keyboard
| Keys | Action |
|---|---|
| Arrow keys | Move by day and week |
| Home / End | To the start and end of the week |
| PageUp / PageDown | By month |