Playground

Date range picker

A button that opens a range calendar and two typed date fields.

  • Built on native elements
  • The trigger is a button naming the field and the current range; it opens a dialog with two text fields and the calendar.
  • Typed fields are labelled Start and End, accept YYYY-MM-DD, apply on Enter or blur and mark aria-invalid with an alert message when the text is not a pickable date.
  • Choosing the end date closes the dialog and returns focus to the trigger; Escape closes without changing.
  • Styles in one file: 03-form-fields.css

Import

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

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add date-range-picker

Usage

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

<div style={{maxWidth: '320px', minHeight: '440px'}}>
  <Field label="Stay">
    <DateRangePicker weekStartsOn={1} />
  </Field>
</div>

Examples

In a field

Props

DateRangePickerProps

PropTypeDefaultDescription
placeholderstring'Pick dates'Text shown on the button while no range is chosen. Default "Pick dates".
formatIntl.DateTimeFormatOptions{dateStyle: 'medium'}Intl options for the dates on the button. Default: medium date.
disabledboolean–Stops the user opening the calendar.
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
[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

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
.calendar-dayrange-calendar.css
.range-calendarrange-calendar.css
.range-cellrange-calendar.css
.calendardate-range-picker.css
.date-range-errordate-range-picker.css
.date-range-fielddate-range-picker.css
.date-range-fieldsdate-range-picker.css
.date-range-popoverdate-range-picker.css
.inputdate-range-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 range; it opens a dialog with two text fields and the calendar.
  • Typed fields are labelled Start and End, accept YYYY-MM-DD, apply on Enter or blur and mark aria-invalid with an alert message when the text is not a pickable date.
  • Choosing the end date closes the dialog and returns focus to the trigger; Escape closes without changing.
  • All range-calendar keyboard behaviour applies inside.

Keyboard

KeysAction
EscapeCloses without changing