Playground

Date picker

A button that opens a calendar and shows the chosen date.

  • Built on native elements
  • The trigger is a button naming the field and the current value; it opens a dialog with the calendar.
  • Choosing a date closes the dialog and returns focus to the trigger; Escape closes without changing.
  • All calendar keyboard behaviour applies inside.
  • Styles in one file: 03-form-fields.css

Import

import '@monoline/css';
import {DatePicker} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add date-picker

Usage

import {DatePicker, Field} from '@monoline/react';

<div style={{maxWidth: '260px', minHeight: '360px'}}>
  <Field label="Due date">
    <DatePicker weekStartsOn={1} />
  </Field>
</div>

Examples

In a field

Clearable

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

Props

DatePickerProps

PropTypeDefaultDescription
placeholderstring'Pick a date'Text shown on the button while no date is chosen. Default "Pick a date".
formatIntl.DateTimeFormatOptions{dateStyle: 'medium'}Intl options for the text on the button. Default: medium date.
disabledboolean–Stops the user opening the calendar.
size"sm" | "md" | "lg"'md'`md` (default), `sm` for dense layouts or `lg` for prominent forms. Heights match Button, Input and Select at each size.
invalidboolean–Marks the field as having an error: sets `aria-invalid` and shows the error border.
classNamestring–Extra class name for the trigger button.
aria-labelstring–Names the control when it is not inside a Field.

Data Attributes

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

AttributeStylesheet
[aria-checked="true"]03-form-fields.css
[aria-invalid="true"]03-form-fields.css
[aria-pressed="true"]03-form-fields.css
[data-disabled]popover.css
[data-highlighted]popover.css
[data-variant="danger"]popover.css
[aria-pressed="true"]calendar.css
[data-outside]calendar.css
[data-today]calendar.css
[data-empty]date-picker.css

CSS classes

ClassStylesheet
.field03-form-fields.css
.field-hint03-form-fields.css
.input03-form-fields.css
.input-bare03-form-fields.css
.input-end03-form-fields.css
.input-lg03-form-fields.css
.input-sm03-form-fields.css
.input-wrap03-form-fields.css
.muted03-form-fields.css
.seg03-form-fields.css
.seg-opt03-form-fields.css
.select03-form-fields.css
.setting03-form-fields.css
.switch03-form-fields.css
.textarea03-form-fields.css
.menu-contentpopover.css
.menu-indicatorpopover.css
.menu-itempopover.css
.menu-item-checkpopover.css
.menu-labelpopover.css
.popoverpopover.css
.calendarcalendar.css
.calendar-daycalendar.css
.calendar-gridcalendar.css
.calendar-headcalendar.css
.calendar-navcalendar.css
.calendar-titlecalendar.css
.calendardate-picker.css
.date-popoverdate-picker.css
.date-triggerdate-picker.css
.popoverdate-picker.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
.field {
  border-color: var(--accent);
}
.field[aria-checked="true"] {
  background: var(--wash);
}

Accessibility

  • The trigger is a button naming the field and the current value; it opens a dialog with the calendar.
  • Choosing a date closes the dialog and returns focus to the trigger; Escape closes without changing.
  • All calendar keyboard behaviour applies inside.
  • With `clearable`, a "Clear date" button in the popover removes the date, closes it and returns focus to the trigger.

Keyboard

KeysAction
EscapeCloses without changing