Date range picker
A button that opens a range calendar and two typed date fields.
SourceStyles source@monoline/react 0.4.0Markdown for AI toolsstable
- 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
| Prop | Type | Default | Description |
|---|---|---|---|
placeholder | string | 'Pick dates' | Text shown on the button while no range is chosen. Default "Pick dates". |
format | Intl.DateTimeFormatOptions | {dateStyle: 'medium'} | Intl options for the dates on the button. Default: medium date. |
disabled | boolean | – | Stops the user opening the calendar. |
invalid | boolean | – | Marks the field as having an error: sets `aria-invalid` and shows the error border. |
className | string | – | Extra class name for the trigger button. |
aria-label | string | – | 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.
| Attribute | Stylesheet |
|---|---|
[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
| Class | Stylesheet |
|---|---|
.field | 03-form-fields.css |
.field-hint | 03-form-fields.css |
.input | 03-form-fields.css |
.input-bare | 03-form-fields.css |
.input-end | 03-form-fields.css |
.input-lg | 03-form-fields.css |
.input-sm | 03-form-fields.css |
.input-wrap | 03-form-fields.css |
.muted | 03-form-fields.css |
.seg | 03-form-fields.css |
.seg-opt | 03-form-fields.css |
.select | 03-form-fields.css |
.setting | 03-form-fields.css |
.switch | 03-form-fields.css |
.textarea | 03-form-fields.css |
.menu-content | popover.css |
.menu-indicator | popover.css |
.menu-item | popover.css |
.menu-item-check | popover.css |
.menu-label | popover.css |
.popover | popover.css |
.calendar | calendar.css |
.calendar-day | calendar.css |
.calendar-grid | calendar.css |
.calendar-head | calendar.css |
.calendar-nav | calendar.css |
.calendar-title | calendar.css |
.calendar | date-picker.css |
.date-popover | date-picker.css |
.date-trigger | date-picker.css |
.popover | date-picker.css |
.calendar-day | range-calendar.css |
.range-calendar | range-calendar.css |
.range-cell | range-calendar.css |
.calendar | date-range-picker.css |
.date-range-error | date-range-picker.css |
.date-range-field | date-range-picker.css |
.date-range-fields | date-range-picker.css |
.date-range-popover | date-range-picker.css |
.input | date-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
| Keys | Action |
|---|---|
| Escape | Closes without changing |