Concepts

State

Let the calendar own its state, or control it from your app, one value at a time.

Root keeps six values:

ValueTypeMeaning
viewone of your view namesThe active view
anchorDateTemporal.PlainDateThe date the visible range is built around
timeZonestring (IANA name)The zone timed events are shown in
selectionyour type, or nullWhat the user selected
focusyour type, or nullWhat has keyboard focus inside the calendar
expandedResourceIdsarray of resource IDsWhich 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.

<Calendar.Root
  events={meetings}
  defaultView="day"
  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.

controlled-state.tsx
export function ControlledCalendar() {
  const [anchorDate, setAnchorDate] = useState(() => Temporal.PlainDate.from("2026-10-08"));

  return (
    <>
      <input
        type="date"
        value={anchorDate.toString()}
        onChange={(event) => {
          if (event.currentTarget.value) {
            setAnchorDate(Temporal.PlainDate.from(event.currentTarget.value));
          }
        }}
      />
      <Calendar.Root
        events={meetings}
        anchorDate={anchorDate}
        onAnchorDateChange={setAnchorDate}
        defaultTimeZone="Europe/Berlin"
        locale="en-US"
        weekRules={weekRules}
      >
        <Calendar.PreviousTrigger>Previous</Calendar.PreviousTrigger>
        <Calendar.NextTrigger>Next</Calendar.NextTrigger>
        <NextWeekButton />
        <Calendar.ActiveView />
      </Calendar.Root>
    </>
  );
}

The props follow one pattern:

UncontrolledControlledHandler
defaultViewviewonViewChange
defaultAnchorDateanchorDateonAnchorDateChange
defaultTimeZonetimeZoneonTimeZoneChange
defaultSelectionselectiononSelectionChange
defaultFocusfocusonFocusChange
defaultExpandedResourceIdsexpandedResourceIdsonExpandedResourceIdsChange

A few rules:

  • undefined means uncontrolled. To control selection or focus with nothing selected, pass null.
  • 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.
  • Root needs a date, a time zone, and a view on its first render. The view can come from defaultView, view, or the first registered view. If one is missing, Root throws calendar-root-requires-anchor-date, calendar-root-requires-time-zone, or calendar-root-requires-view.

What a handler hears

Every change handler gets the new value and a detail:

FieldTypeMeaning
slicestringWhich value changed, such as "view" or "anchorDate"
previousthe value's typeThe value before the change
controlledbooleanWhether a prop controls the value
reasonstringWhy it changed. See below
sourcestringWho caused it. See below
eventEvent, or absentThe DOM event behind it, such as a button's click. Absent for code and agents
cancel()functionStops the change. An uncontrolled value goes back to previous
canceledbooleanWhether cancel() was called

reason is one of:

  • "next-press", "previous-press" or "today-press": a press of Calendar.NextTrigger, Calendar.PreviousTrigger or Calendar.TodayTrigger.
  • "input-change": a choice in Calendar.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 as actions.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 Calendar, meetings and weekRules from the Quick start:

tracked-calendar.tsx
"use client";

import { CalendarToolbar } from "@/components/calendar/calendar-toolbar";

import { Calendar, meetings, weekRules } from "./calendar";

/** Records how the calendar is navigated, and keeps the month view for people. */
export function TrackedCalendar({ track }: { readonly track: (entry: string) => void }) {
  return (
    <Calendar.Root
      label="Team calendar"
      events={meetings}
      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"
        track(`${detail.reason} by ${detail.source} to ${date.toString()}`);
      }}
      onViewChange={(view, detail) => {
        if (view === "month" && detail.source === "agent") detail.cancel();
      }}
    >
      <Calendar.Frame className="flex h-[640px] flex-col rounded-xl border">
        <CalendarToolbar calendar={Calendar} />
        <Calendar.Viewport className="min-h-0 flex-1">
          <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:

<button onClick={(event) => actions.navigateNext({ event: event.nativeEvent })}>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:

  • useCalendarState() returns all six values.
  • useCalendarSelector(selector) returns one derived value and re-renders only when it changes.
  • useCalendarActions() returns setView, setAnchorDate, setTimeZone, setSelection, setFocus, setExpandedResourceIds, navigateNext, navigatePrevious, navigateToday, proposeEventChange, and checkEventChange.
  • 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() returns state, actions, and meta together.
  • useVisibleRange() and useViewProjection() return what the active view shows. See Custom views.
controlled-state.tsx
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.

selection.tsx
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>
  );
}

On this page