State
Let the calendar own its state, or control it from your app, one value at a time.
Root keeps six values:
| Value | Type | Meaning |
|---|---|---|
view | one of your view names | The active view |
anchorDate | Temporal.PlainDate | The date the visible range is built around |
timeZone | string (IANA name) | The zone timed events are shown in |
selection | your type, or null | What the user selected |
focus | your type, or null | What has keyboard focus inside the calendar |
expandedResourceIds | array of resource IDs | Which resource groups are expanded |
Each value can be uncontrolled (the calendar owns it) or controlled (your app owns it), independently of the others.
Uncontrolled
Pass a default prop and the calendar manages the value from then on. Defaults are read once, when
Root mounts.
export function UncontrolledCalendar() {
return (
<Calendar.Root
events={seed}
defaultView="list"
defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
defaultTimeZone="Europe/Berlin"
locale="en-US"
weekRules={weekRules}
>
<Calendar.ActiveView />
</Calendar.Root>
);
}Controlled
Pass the value and a change handler. The calendar never changes a controlled value itself. When the user clicks Next, it calls your handler with the new value, and you decide whether to store it.
This example controls the date so a date input outside the calendar stays in sync. It uses the
Calendar from the Quick start.
export function ControlledCalendar() {
const [anchorDate, setAnchorDate] = createSignal(Temporal.PlainDate.from("2026-10-08"));
return (
<>
<input
type="date"
value={anchorDate().toString()}
onInput={(event) => {
if (event.currentTarget.value) {
setAnchorDate(Temporal.PlainDate.from(event.currentTarget.value));
}
}}
/>
<Calendar.Root
events={seed}
anchorDate={anchorDate()}
onAnchorDateChange={(date) => setAnchorDate(date)}
defaultTimeZone="Europe/Berlin"
locale="en-US"
weekRules={weekRules}
>
<Calendar.PreviousTrigger>Previous</Calendar.PreviousTrigger>
<Calendar.NextTrigger>Next</Calendar.NextTrigger>
<NextWeekButton />
<Calendar.ActiveView />
</Calendar.Root>
</>
);
}A controlled prop takes the signal's value, anchorDate={anchorDate()}, and the calendar follows
the signal.
The props follow one pattern:
| Uncontrolled | Controlled | Handler |
|---|---|---|
defaultView | view | onViewChange |
defaultAnchorDate | anchorDate | onAnchorDateChange |
defaultTimeZone | timeZone | onTimeZoneChange |
defaultSelection | selection | onSelectionChange |
defaultFocus | focus | onFocusChange |
defaultExpandedResourceIds | expandedResourceIds | onExpandedResourceIdsChange |
A few rules:
undefinedmeans uncontrolled. To controlselectionorfocuswith nothing selected, passnull.- Handlers also run for uncontrolled values, after the calendar updates them. The second argument says what changed, why, and who asked. See what a handler hears.
- If you haven't applied a change the calendar asked for, the handler also hears a later request for the value you have. For example, Today after a scroll you deferred. Apply the latest value you were given, and you'll drop the earlier change.
Rootneeds a date, a time zone, and a view on its first render. The view can come fromdefaultView,view, or the first registered view. If one is missing,Rootthrowscalendar-root-requires-anchor-date,calendar-root-requires-time-zone, orcalendar-root-requires-view.
What a handler hears
Every change handler gets the new value and a detail:
| Field | Type | Meaning |
|---|---|---|
slice | string | Which value changed, such as "view" or "anchorDate" |
previous | the value's type | The value before the change |
controlled | boolean | Whether a prop controls the value |
reason | string | Why it changed. See below |
source | string | Who caused it. See below |
event | Event, or absent | The DOM event behind it, such as a button's click. Absent for code and agents |
cancel() | function | Stops the change. An uncontrolled value goes back to previous |
canceled | boolean | Whether cancel() was called |
reason is one of:
"next-press","previous-press"or"today-press": a press ofCalendar.NextTrigger,Calendar.PreviousTriggerorCalendar.TodayTrigger."input-change": a choice inCalendar.ViewSwitcher."keyboard-navigation": a key in a view that moves focus or the visible range, such as an arrow key or Page Down."focus-change": focus a person moved onto a cell or an event, by clicking it or tabbing to it."resource-toggle": a resource expanded or collapsed."imperative": an action called from code, such asactions.setView("month"). It's also the reason for anything an agent does.
source is one of "mouse", "touch", "pen", "keyboard", "virtual", "agent" or
"programmatic". "keyboard" is a person's keys, on a toolbar button and in a view: arrow-key
navigation, moving focus and expanding a resource report it. "virtual" is a click with no
pointer or key behind it, which may come from assistive technology. "agent" is an AI agent
acting through the agent bridge, and anything its step causes.
"programmatic" is your own code.
This calendar records how people navigate and keeps agents out of the month view. It uses the
TeamCalendar from the views overview, which has an agenda and a
month view:
import { seed, weekRules } from "./app";
import { TeamCalendar as Calendar } from "./team-calendar";
/** Records how the calendar is navigated, and keeps the month view for people. */
export function TrackedCalendar(props: { readonly track: (entry: string) => void }) {
return (
<Calendar.Root
label="Team calendar"
events={seed}
defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
defaultTimeZone="Europe/Berlin"
locale="en-US"
weekRules={weekRules}
onAnchorDateChange={(date, detail) => {
// "next-press by mouse to 2026-10-15", "imperative by agent to 2026-11-02"
props.track(`${detail.reason} by ${detail.source} to ${date.toString()}`);
}}
onViewChange={(view, detail) => {
if (view === "month" && detail.source === "agent") detail.cancel();
}}
>
<Calendar.Frame>
<Calendar.Toolbar>
<Calendar.PreviousTrigger>Previous</Calendar.PreviousTrigger>
<Calendar.NextTrigger>Next</Calendar.NextTrigger>
<Calendar.Title />
</Calendar.Toolbar>
<Calendar.Viewport>
<Calendar.ActiveView />
</Calendar.Viewport>
</Calendar.Frame>
</Calendar.Root>
);
}cancel() puts an uncontrolled value back as it was. For a controlled value it does nothing you
couldn't do yourself: the value changes only when you store it.
An action you call can say why and who. Pass the DOM event that led to it, and the calendar works
out the source:
export function NextButton() {
const actions = Calendar.useCalendarActions();
return (
<button type="button" onClick={(event) => actions.navigateNext({ event })}>
Next
</button>
);
}Every action takes the same options as its last argument: { event?, reason?, source? }.
Without them, a call from your code reads reason: "imperative" and source: "programmatic".
Reading and changing state
Any component inside Root can use the hooks on your calendar. A hook that reads a value returns an accessor, so call it where you use the value: state().view:
useCalendarState()returns all six values.useCalendarSelector(selector)returns one derived value, and its readers run again only when it changes.useCalendarActions()returnssetView,setAnchorDate,setTimeZone,setSelection,setFocus,setExpandedResourceIds,navigateNext,navigatePrevious,navigateToday,proposeEventChange, andcheckEventChange.useCalendarMeta()returns everything else: the event snapshot, resources, the environment, the active view and the registered views, diagnostics, the instance ID, and element IDs and refs.useCalendar()returnsstate,actions, andmetatogether.useVisibleRange()anduseViewProjection()return what the active view shows. See Custom views.
const selectAnchorDate = (state: CalendarPublicState) => state.anchorDate;
function NextWeekButton() {
const anchorDate = Calendar.useCalendarSelector(selectAnchorDate);
const actions = Calendar.useCalendarActions();
return (
<button type="button" onClick={() => actions.setAnchorDate(anchorDate().add({ weeks: 1 }))}>
Skip a week
</button>
);
}A selector can live outside the component, as above, or inline. Actions called one after another
build on each other, so navigateNext() twice in one click moves two steps, controlled or not.
Selection and focus types
You choose the shape of selection and focus. Pass their types as the third and fourth type
arguments of createCalendar, after the event and resource types. Time stores the values as they
are.
import { createCalendar } from "@moltenship/calendar-solid";
import { eventAdapter, type Meeting } from "./calendar";
type Selection = { readonly eventId: string } | { readonly date: Temporal.PlainDate };
const Calendar = createCalendar<Meeting, never, Selection>()({ eventAdapter });
export function SelectStandup() {
const actions = Calendar.useCalendarActions();
return (
<button type="button" onClick={() => actions.setSelection({ eventId: "standup" })}>
Select standup
</button>
);
}Time and time zones
Timed, all-day, and floating events, exclusive end times, and daylight saving time.
Overview
How views work, how to register and switch them, the registry's week and day, month, year and agenda, their scrolling versions, the resource columns and the resource timeline, and the engine's layouts a view draws.