Show and edit recurring events

Expand series for the dates on screen, and ask which events a change applies to.

Try it in the Solid demo: drag a Standup in the week, and the calendar asks whether the change applies to this event, this and following events, or all events. The change waits on screen while it asks.

Live. The calendar this guide builds. Pick a standup, press Delete, and choose which of the standups to delete.

This guide builds such a calendar with @moltenship/calendar-recurrence. It expands each series into its occurrences for the dates on screen, and turns a change to one occurrence into what to save. The registry's recurrence-scope-dialog asks the question. Series and occurrences explains the model behind it.

Install

The recurrence package is separate from the calendar. It imports no UI framework, so you can also expand series on a server.

pnpm add @moltenship/calendar-recurrence

The dialog that asks for the scope is UI source, like the views. Add it with the shadcn CLI, as UI source describes. It brings the controls' dialog and button:

npx shadcn@latest add @moltenship/recurrence-scope-dialog

Wire the adapters

The calendar shows occurrences, not your events. A RecurrenceOccurrence is one occurrence of a series, or a one-off event passed through, and createOccurrenceAdapter turns your event adapter into the calendar's adapter for them. A recurrence adapter beside it reads what makes an event a series' master, or an override of one occurrence. Together, they're your RecurrenceAdapters.

An app without an event type of its own can store RecurringCalendarEvents: core's CalendarEvent with an optional recurrence and override. createCanonicalRecurrenceAdapter returns both adapters for them:

team-calendar.tsx
import {
  applyRecurrenceEdit,
  createCanonicalRecurrenceAdapter,
  createOccurrenceAdapter,
  createOccurrenceExpander,
  isRecurringChange,
  recurrenceEditScopes,
  resolveRecurrenceEdit,
  type RecurrenceEditScope,
  type RecurrenceOccurrence,
  type RecurringCalendarEvent,
} from "@moltenship/calendar-recurrence";
import {
  createCalendar,
  type CalendarEventChange,
  type CalendarFocus,
  type CalendarVisibleRange,
  type EventId,
  useCalendarFocus,
} from "@moltenship/calendar-solid";
import { createMemo, createSignal } from "solid-js";

import { createAgendaView } from "@/components/calendar/list-view/agenda-view";
import { useRecurrenceScopePrompt } from "@/components/calendar/recurrence-scope-dialog/use-recurrence-scope-prompt";
import { Button } from "@/components/calendar/ui/button";

/** A series' master has a `recurrence`; any other event happens once. */
export type TeamEvent = RecurringCalendarEvent<null>;

/** What the calendar shows: one occurrence of a series, or a one-off event. */
export type TeamOccurrence = RecurrenceOccurrence<TeamEvent, string>;

export const adapters = createCanonicalRecurrenceAdapter<null>();

export const Calendar = createCalendar<TeamOccurrence>()({
  // Occurrences are the calendar's events. It reads their titles through your adapter.
  eventAdapter: createOccurrenceAdapter(adapters.event),
  views: [createAgendaView<TeamOccurrence>()],
});

With your own event type, write the recurrence adapter yourself, as the reference's Adapters describes.

Expand the dates on screen

A series can be endless, so expand it only for the dates the calendar needs. The calendar reports them through onVisibleRangeChange:

team-calendar.tsx
// One expander for as long as the calendar is mounted: it keeps its work for series that
// didn't change, and returns the same occurrence objects for them.
const expander = createOccurrenceExpander(adapters);
const [range, setRange] = createSignal({ end: today.add({ days: 7 }), start: today });
const occurrences = createMemo(
  () => expander.expand(events(), { range: range(), timeZone }).occurrences,
);
const onVisibleRangeChange = ({ loadRange }: CalendarVisibleRange) => setRange(loadRange);
  • One expander. Create it once, in the component's body, which runs once. It keeps its work for each series between calls, and gives back the same occurrence objects for events that didn't change, so the calendar and its views skip them.
  • A memo over events and range. Expansion runs again only when your events or the dates change. A new array holding the same event objects is cheap: unchanged series reuse their work.
  • loadRange, not range. Scrolling views render a page of days on either side of the ones they show. loadRange includes those pages; range is only what's visible.
  • The first render. The calendar reports its range after it first renders, so the signal starts from the week it opens on. Without a first guess, the first frame has no events.
  • Time zones. timeZone is the calendar's zone, which places the range's dates for timed series. Series repeat in their own sourceTimeZone, or, for events without one, in the expander's defaultTimeZone, which is UTC unless you set it.

expansion.issues lists what the expander couldn't read, such as an invalid rule or an override whose series isn't loaded, with each event and its position. Bad data never throws: the rest of the series and the other events still show.

Ask which events a change applies to

When someone changes an occurrence, the calendar calls onEventChange with a change whose event is the occurrence. useRecurrenceScopePrompt from the dialog you added returns ask, which opens the dialog and resolves with the scope picked, and dialog, to render once:

team-calendar.tsx
const { ask, dialog } = useRecurrenceScopePrompt();

async function onEventChange(change: CalendarEventChange<TeamOccurrence, string, string>) {
  // A new event, or a change to a one-off event, needs no question.
  let scope: RecurrenceEditScope = "this";
  if (isRecurringChange(change)) {
    const scopes = recurrenceEditScopes(change, adapters, { timeZone });
    // None applies, so there's nothing to ask: throwing rolls the change back.
    if (scopes.length === 0) throw new Error("This repeating event can't change that way.");
    const picked = await ask({
      action: change.cause === "delete" ? "delete" : "edit",
      eventTitle: change.event.event.title,
      scopes,
    });
    // An `AbortError` is announced as a cancel, not as a change that couldn't be saved.
    if (picked === null) throw new DOMException("Cancelled", "AbortError");
    scope = picked;
  }

  const edit = resolveRecurrenceEdit(change, scope, adapters, {
    // Picked now, so the IDs of a "following" edit's new series are known.
    newSeriesId: crypto.randomUUID(),
    occurrences: occurrences(),
    timeZone,
  });
  if (edit.type === "rejected") throw new Error(edit.message);
  // Save the edit on your server here. The change stays pending until this function returns.
  // A one-off event's edit is `type: "event"`: apply its `change` as any calendar does.
  if (edit.type === "series") {
    setEvents((current) =>
      applyRecurrenceEdit(current, edit, { createId: () => crypto.randomUUID() }),
    );
    // "following" and "all" give the occurrences new IDs. Focus follows them, and the calendar
    // moves it to the occurrence under its new ID.
    setFocus((current) => renamed(current, edit.occurrenceIds));
  }
}
  1. isRecurringChange says whether the change is to an occurrence of a series. A new event, or a change to a one-off event, needs no question.
  2. ask opens the dialog. action picks its wording for an edit or a delete, and scopes comes from recurrenceEditScopes, which offers only the scopes that apply: no "This and following events" on a series' first occurrence, and only "This event" when the rule can't follow the change, such as the 28th of each month dragged to a 29th. When none applies, the list is empty and there's nothing to ask: tell the user why, and roll the change back.
  3. Cancel resolves null. Throwing rolls the change back, as any error in onEventChange does. Throw an AbortError, as the handler does, and the calendar's announcements say the change was cancelled rather than that it couldn't be saved.
  4. resolveRecurrenceEdit turns the change into an edit: what to save for that scope. Pass the calendar's timeZone to it and to recurrenceEditScopes, so the change is replayed on the series' own clock. A change that needs no scope comes back as type: "event", with your event unwrapped from the occurrence, to apply as you would without recurrence. A scope that can't apply comes back as type: "rejected", with a reason and a message.
  5. Save the edit, below. The change stays pending until onEventChange returns.

While the dialog is open, the change waits on screen as pending. Only the changed occurrence shows it: the calendar keeps pending changes per event and knows nothing about series, so for "This and following events" or "All events" the rest of the series moves when your events change.

Deleting

The views don't delete events; your own UI does, with proposeEventChange. The change goes through the same onEventChange, and ask uses the dialog's wording for a delete:

team-calendar.tsx
/** Deletes the event last focused in the agenda, through `onEventChange`. */
function DeleteFocused() {
  const focused = useCalendarFocus((focus) =>
    focus?.kind === "event" ? String(focus.eventId) : null,
  );
  const { proposeEventChange } = Calendar.useCalendarActions();
  return (
    <Button
      disabled={focused() === null}
      onClick={() => {
        const eventId = focused();
        if (eventId !== null) void proposeEventChange({ cause: "delete", eventId });
      }}
      size="sm"
      variant="outline"
    >
      Delete
    </Button>
  );
}

Save the edit

A series edit lists its writes as plain data, so you can send it to a server as it is or apply it to your own store. If your events are RecurringCalendarEvents, applyRecurrenceEdit applies it and returns the new array, as onEventChange above does. createId names the events it creates: overrides, and the series a "This and following events" edit starts when you didn't pick its ID.

With your own event type or a database, write the edit's series, newSeries, override and otherOverrides yourself: the reference describes each. The edit describes placement and recurrence only, so copy a changed title or other fields yourself.

Keep the selection

An occurrence's ID is its series' ID and its original start, such as standup::2026-10-05T07:00:00Z. It's stable across views, time zones and reloads, and when "This event" moves the occurrence, since its override keeps the original start.

"This and following events" and "All events" change the original starts, and so the IDs. edit.occurrenceIds maps old IDs to new ones, and the handler above moves the keyboard focus with it:

  • Control focus with onFocusChange, and map it before onEventChange returns. ask resolves once the dialog has closed and focus is back on the occurrence, and the calendar then moves focus to the occurrence under its new ID.
  • Pass occurrences, the expansion you give the calendar, so the map covers every occurrence on screen, not only the changed one.
  • Pass newSeriesId for "This and following events", so the map can name the new series' occurrences. Pick it before you save, as you would for an optimistic create.
  • Map anything else that holds occurrence IDs the same way, such as a selection, an open details panel or a URL.

Put it together

The occurrences go to events, the handlers and the focus to Root, and the dialog renders beside it:

team-calendar.tsx
return (
  <>
    <Calendar.Root
      defaultAnchorDate={today}
      defaultTimeZone={timeZone}
      defaultView="agenda"
      events={occurrences()}
      focus={focus()}
      locale="en-US"
      onEventChange={onEventChange}
      onFocusChange={setFocus}
      onVisibleRangeChange={onVisibleRangeChange}
      weekRules={{ firstDay: 1, minimalDays: 4, weekend: [6, 7] }}
    >
      <Calendar.Frame class="flex h-dvh flex-col">
        <DeleteFocused />
        <Calendar.Viewport class="min-h-0 flex-1">
          <Calendar.ActiveView />
        </Calendar.Viewport>
      </Calendar.Frame>
    </Calendar.Root>
    {dialog}
  </>
);

The dialog

The dialog shows one button per scope offered, always in the same order, then Cancel. Focus starts on the narrowest scope offered, usually "This event".

KeyWhat it does
Arrow keysMove between the scopes, wrapping at the ends. Left and Right follow RTL
Tab, Shift+TabMove through the scopes and Cancel, and stay inside the dialog
Enter, SpacePick the focused scope, or cancel
EscapeCancel

When it closes, focus goes back to where it was, such as the event, and only then does ask resolve. Safari skips buttons on Tab unless a setting says otherwise, so the arrow keys reach every scope there.

The wording, English, is in recurrence-scope.ts beside the dialog, to edit or translate. Its look comes from recurrence-scope-dialog.styles.ts and the kit's dialog.tsx and button.tsx. To use a dialog of your own, see Use your own controls.

On this page