Date picker
A button that opens a calendar and shows the chosen date.
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 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
| Prop | Type | Default | Description |
|---|---|---|---|
placeholder | string | 'Pick a date' | Text shown on the button while no date is chosen. Default "Pick a date". |
format | Intl.DateTimeFormatOptions | {dateStyle: 'medium'} | Intl options for the text on the button. Default: medium date. |
disabled | boolean | – | 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. |
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 |
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 |
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
| Keys | Action |
|---|---|
| Escape | Closes without changing |