Playground

Calendar

A month grid for picking one date.

  • 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

Clearable

clearable adds a "Clear date" button; onValueChange receives null.

Props

CalendarProps

PropTypeDefaultDescription
valueDate | null–The selected date when controlled; `null` means none. Pair with `onValueChange`.
defaultValueDate | nullnullThe 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`).
clearablebooleanfalseAdds a "Clear date" button under the grid that resets the value to `null`. Default false.
weekStartsOn0 | 10First day of the week: 0 = Sunday, 1 = Monday.
minDate–Earliest selectable date; earlier days are disabled.
maxDate–Latest selectable date; later days are disabled.
localestring–BCP 47 locale for month and day names.

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[aria-pressed="true"]calendar.css
[data-outside]calendar.css
[data-today]calendar.css

CSS classes

ClassStylesheet
.calendarcalendar.css
.calendar-daycalendar.css
.calendar-gridcalendar.css
.calendar-headcalendar.css
.calendar-navcalendar.css
.calendar-titlecalendar.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

KeysAction
Arrow keysMove by day and week
Home / EndTo the start and end of the week
PageUp / PageDownBy month