Date picker API
Props, slots, labels and styling of the slotsmith Date picker.
Slots
DatePicker has 15 slots. Pass a replacement for any of them in components; every slot you leave out keeps its fallback. Element slots receive DOM props, so a library's own element fits as it is; widget slots receive named props and usually need a few lines of adapter.
| Name | Kind | Props it receives | Default fallback | data-* attributes |
|---|---|---|---|---|
Root | <element> | DOM props:
| Fallback source |
|
Trigger | <element> | DOM props:
| Fallback source |
|
Input | <element> | DOM props:
| Fallback source |
|
Toggle | <element> | DOM props:
| Fallback source |
|
Value | {widget} |
| Fallback source | — |
Icon | {widget} |
| Fallback source | — |
Clear | {widget} |
| Fallback source | — |
Popup | <element> | DOM props:
| Fallback source |
|
Calendar | <element> | DOM props:
| Fallback source | — |
Caption | {widget} |
| Fallback source | — |
Nav | {widget} |
| Fallback source | — |
Weekday | {widget} |
| Fallback source | — |
Day | <element> | DOM props:
| Fallback source |
|
DayContent | {widget} |
| Fallback source | — |
Footer | {widget} |
| Fallback source | — |
Props
Every prop of DatePicker, grouped as in the library's documentation. Controlled state comes in pairs: pass a value with its change handler, or only the default to leave the state inside the component.
| Name | Type | Default | Description |
|---|---|---|---|
| Value and mode | |||
modesingle mode | "single" | — | One date. The default mode. |
moderequiredmultiple mode | "multiple" | — | Any number of dates, toggled one click at a time. |
moderequiredrange mode | "range" | — | A start and an end: the first click sets the start, the second the end. |
valuesingle mode | ISODate | | — | The picked date, or |
valuemultiple mode | ISODate | — | The picked dates. |
valuerange mode | DateRange | | — | The picked range. Either end may be missing while picking. |
defaultsingle mode | ISODate | | — | The picked date while uncontrolled. |
defaultmultiple mode | ISODate | — | The picked dates while uncontrolled. |
defaultrange mode | DateRange | | — | The picked range while uncontrolled. |
onsingle mode | ( | — | The new date, or |
onmultiple mode | ( | — | The new dates, sorted, always an array. |
onrange mode | ( | — | The new range, or |
clearable | boolean | true | Whether the clear control is offered. Defaults to |
close | boolean |
| Whether picking closes the popup. Defaults to |
value | DateValueFormat |
| How the days the picker exchanges with you are written: |
time | string | the browser's own | The time zone the calendar works in: an IANA name such as |
name | string | — | The form field name. The root then holds a hidden input of that name per picked day, written as |
| Calendar | |||
locale | LocaleInput | the provider's, then | The language: a locale object, or a BCP 47 tag. A tag formats dates and names with |
week | WeekStart | the locale's own first day | The first column of the grid. Defaults to the locale's own first day. |
weekday | "narrow" | | narrow | How long the column headers are. |
presets | DatePickerPreset | — | Shortcuts shown under the grid. A date preset in range mode picks that one day. |
| Bounds | |||
min | ISODate | — | Nothing before this date can be picked, and the calendar does not page past it. |
max | ISODate | — | Nothing after this date can be picked, and the calendar does not page past it. |
disabled | ( | — | Blocks individual dates — weekends, holidays, days already booked. They stay focusable. |
| Open state | |||
open | boolean | — | Whether the popup is open. |
default | boolean | — | Whether the popup starts open. |
on | ( | — | Told when the popup opens or closes. |
disabled | boolean | — | Disables the whole control. Separate from |
invalid | boolean | — | The value failed validation. Sets |
on | ( | — | Told when focus leaves the whole control, for form libraries. |
| Display | |||
trigger | DatePickerTriggerKind | — | What opens the calendar. |
open | boolean | false | With the |
placeholder | string | — | Shown when nothing is picked. With the |
format | Intl. | { | How the trigger formats a date. Defaults to |
placement | PopupPlacement | bottom | Which side of the trigger the popup prefers. Defaults to |
popup | number | 4 | Gap between trigger and popup, in pixels. Defaults to 4. |
portal | PortalTarget | false | Renders the popup in a portal: |
| Slots and labels | |||
components | Partial< | — | Replace any part; the rest fall back to |
labels | Partial< | — | Override any string. Wins over |
slot | DatePickerSlotProps | — | Extra DOM props for the element parts. |
Any other prop is passed to the root <div> element.
Labels & locales
Every string DatePicker shows or announces, with its English default. Pass labels to change some of them for one component, or locale to switch every string to another language. The demo below does both.
| Key | Type | English default | Description |
|---|---|---|---|
placeholder | string | "Pick a date" | Trigger text when nothing is picked, and the trigger's default accessible name. |
clear | string | "Clear date" | Accessible name for the clear control. |
open | string | "Open calendar" | Accessible name for the calendar button beside the text field. |
previous | string | "Previous month" | Accessible name for the previous-month control. |
next | string | "Next month" | Accessible name for the next-month control. |
today | string | "Go to today" | Label for the control that jumps to today's month without picking it — a navigation verb, not the bare word "today", so it reads apart from the presets. |
month | string | "Month" | Accessible name for the month dropdown. |
year | string | "Year" | Accessible name for the year dropdown. |
dialog | string | "Choose a date" | Accessible name for the popup. |
count | ( | count(prints | Multiple mode: how the trigger summarises more than two dates. |
range | ( | rangeStart(prints | Range mode, when only the start is picked. Receives the formatted start. |
range | ( | range(prints | Range mode, when both ends are picked. Receives both formatted ends. |
import { DatePicker } from "slotsmith/date-picker";
import { de } from "slotsmith/locales/de";
export default function Labels() {
return (
<DatePicker
mode="multiple"
// Every string in German, from the ready-made pack; month and weekday names come from Intl…
locale={de}
// …except these two, replaced for this picker only.
labels={{ openCalendar: "Kalender zeigen", today: "Heute anzeigen" }}
aria-label="Urlaubstage"
/>
);
}The ready-made language packs, right-to-left support and app-wide locales are on the Languages page.
Styling
The class names the fallbacks of DatePicker put on their elements, and the tokens its stylesheet reads. Set a token on the component, or on any element around it, to restyle it; target a class only for what no token covers.
| Class | Slot |
|---|---|
.sdp | |
.sdp__header | — |
.sdp__cell | — |
.sdp__weekdays | — |
.sdp__columnheader | — |
.sdp__week | — |
.sdp__chevron | — |
.sdp__icon | |
.sdp__today-icon | — |
.sdp__clear | |
.sdp__caption | |
.sdp__select | — |
.sdp__nav | |
.sdp__weekday | |
.sdp__footer | |
.sdp__preset | — |
.sdp__preset--today | — |
.sdp__today | — |
.sdp__trigger | |
.sdp__input | |
.sdp__toggle | |
.sdp__value | |
.sdp__value--empty | — |
.sdp__popup | |
.sdp__calendar | |
.sdp__day |
| Token | Layer |
|---|---|
--sdp-accent | This component |
--sdp-border | This component |
--sdp-cell | This component |
--sdp-danger | This component |
--sdp-font-size | This component |
--sdp-gap | This component |
--sdp-hover | This component |
--sdp-muted | This component |
--sdp-on-accent | This component |
--sdp-radius | This component |
--sdp-surface | This component |
--sdp-text | This component |
--ss-accent | Shared by every component |
--ss-border | Shared by every component |
--ss-danger | Shared by every component |
--ss-font-size | Shared by every component |
--ss-hover | Shared by every component |
--ss-muted | Shared by every component |
--ss-on-accent | Shared by every component |
--ss-radius | Shared by every component |
--ss-surface | Shared by every component |
--ss-text | Shared by every component |
Every token switches to its dark value under .dark, [data-theme="dark"], on the page or on any element around the component.