Calendar
A month-grid date picker with optional month-picking mode and Temporal.PlainDate binding.
Usage
Use standalone.
<Calendar {...props} />Anatomy
The class attribute values represent part names, and conditional indicates elements that are rendered conditionally. Other attributes represent their corresponding props. While picking, children renders inside middle and wins over the embedded MonthPicker.
<div class="whole" role="group">
<div class="top">
<button class="left" type="button">{left}</button>
<button class="label" type="button">{label}</button>
<button class="right" type="button">{right}</button>
</div>
<div class="middle">
<div class="main" role="grid">
<div class="aux" role="row" data-header>
<span class="extra" role="columnheader" data-header>{weekday}</span>
</div>
<div class="aux" role="row">
<button class="extra" role="gridcell">{day}</button>
</div>
</div>
{#if children}{children}{:else}<MonthPicker />{/if} while picking
</div>
<div class="bottom" conditional>{bottom}</div>
</div>- Left and right buttons page
display; the label button togglespicking. - While picking,
childrenrenders in the middle slot and wins over the embeddedMonthPicker. - The
bottomsnippet receives a control object (setToday,clear), thepickingstate, and the variant. - Enabled day clicks and Enter or Space select one
Temporal.PlainDate. - Day cells expose
data-today,data-selected,data-outside,data-disabled, anddata-weekday. - The weekday header row and each week row both use the
auxpart; only the header row and its column headers carrydata-header, which separates header-only from day-only styling. - Arrow keys, Home, End, PageUp, PageDown, and Shift+PageUp/PageDown update roving focus.
Props
| Name | Type | Default | Description |
|---|---|---|---|
value | Temporal.PlainDate | - | Bindable selected date |
display | Temporal.PlainYearMonth | - | Bindable shown year-month for calendar paging |
picking | boolean | false | Bindable state that shows the embedded MonthPicker instead of the day grid |
min | Temporal.PlainDate | - | Lower date bound; dates before it are disabled |
max | Temporal.PlainDate | - | Upper date bound; dates after it are disabled |
isDisabled | (d: Temporal.PlainDate) => boolean | - | Custom predicate that disables matching dates |
outsideDays | boolean | false | Show outside-month days in the grid |
fixedWeeks | boolean | false | Render a fixed six-week grid |
firstDayOfWeek | number | 0 | First weekday, where 0 = Sunday |
locale | string | - | Locale for weekday and heading labels |
label | Snippet | - | Heading snippet |
left | Snippet | - | Previous-button snippet |
right | Snippet | - | Next-button snippet |
weekday | Snippet | - | Weekday label snippet |
day | Snippet | - | Day cell snippet |
bottom | Snippet | - | Bottom-area snippet; receives a control object (setToday, clear), the picking state, and the variant |
children | Snippet | - | Overrides the middle slot while picking; wins over monthPicker |
monthPicker | MonthPickerProps | - | Nested config bag spread into the embedded MonthPicker; Calendar owns the displayed month, bounds, and variant |
transition | TransitionProp | - | Optional transition function and params for switching between the day grid and month picker |
pageTransition | TransitionProp | - | Optional transition that slides the day grid when display pages |
styling | SVSClass | - | Styling override |
variant | SVSVariant | NEUTRAL | Variant passed to navigation and container parts |
Styling
To learn more, see Styling.
Variant Management
Selected days render with active, disabled days render with inactive, and other day cells use neutral. Navigation and container parts receive the supplied variant.
Default Class Name
svs-calendar
Behavior
- Left/right buttons page
display; the label toggles the picking slot. - While picking,
childrenrenders in the middle slot and wins over the embeddedMonthPicker. - The
bottomsnippet receives a control object (setToday,clear), thepickingstate, and the variant. - Enabled day clicks and Enter/Space select a single
Temporal.PlainDate. - Day cells expose
data-today,data-selected,data-outside,data-disabled, anddata-weekday. - Arrow, Home/End, PageUp/PageDown, and Shift+PageUp/PageDown update roving focus.
- The grid re-keys when
displaychanges; optionalpageTransitionapplies to the day-grid page change.
Accessibility
Keyboard Interactions
| Key | Description |
|---|---|
ArrowLeft / ArrowRight | Moves focus one day backward or forward |
ArrowUp / ArrowDown | Moves focus one week backward or forward |
Home / End | Moves focus to the start or end of the focused week |
PageUp / PageDown | Moves focus one month backward or forward |
Shift + PageUp / Shift + PageDown | Moves focus one year backward or forward |
Enter / Space | Selects the focused day |
Clicking an enabled day also selects it.
ARIA Roles and Attributes
The component applies these automatically:
- Root (
whole):role="group"andaria-labelgenerated from the current displayed month. - Caption button (
label):aria-expandedfor the month/year picker state. - Grid (
main):role="grid"andaria-labelledbypointing to the caption button; it contains weekday and week rows. - Weekday row (
aux):role="row"containing column headers. - Weekday header:
role="columnheader"with anaria-labelfor the full weekday name. - Day cell:
role="gridcell", rovingtabindex,aria-selected,aria-disabled,aria-current="date"on today, and a per-datearia-label.
The root already has a built-in accessible name such as the current month. Provide clear custom label, left, right, and day snippets if you replace the default visible text.
Exports
Types
interface CalendarProps {
value?: Temporal.PlainDate; // bindable; selected date
display?: Temporal.PlainYearMonth; // bindable; shown month
picking?: boolean; // bindable (false)
min?: Temporal.PlainDate;
max?: Temporal.PlainDate;
isDisabled?: (d: Temporal.PlainDate) => boolean;
outsideDays?: boolean; // (false)
fixedWeeks?: boolean; // (false)
firstDayOfWeek?: number; // (0=Sun)
locale?: string;
label?: Snippet<[Temporal.PlainYearMonth, string, boolean]>;
left?: Snippet<[string]>;
right?: Snippet<[string]>;
weekday?: Snippet<[number, string]>;
day?: Snippet<[DayCtx]>;
bottom?: Snippet<[CalendarCtl, boolean, string]>;
children?: Snippet;
monthPicker?: Omit<MonthPickerProps, "value" | "min" | "max" | "variant">;
transition?: TransitionProp;
pageTransition?: TransitionProp;
styling?: SVSClass;
variant?: SVSVariant; // (VARIANT.NEUTRAL)
}
type CalendarReqdProps = never;
type CalendarBindProps = "value" | "display" | "picking";
type DayCtx = {
date: Temporal.PlainDate;
variant: string;
weekday: number;
today: boolean;
selected: boolean;
outside: boolean;
disabled: boolean;
};
type CalendarCtl = {
setToday: () => void;
clear: () => void;
};
type TransitionProp = {
fn?: (node: HTMLElement, params: any, options: { direction: "in" | "out" | "both" }) => import("svelte/transition").TransitionConfig;
params?: unknown;
};Others
No additional exports are available.
Examples
The example code uses Tailwind CSS along with SVSClass.