Vanilla Breeze

version-switcher

Surface and switch between versions of a page over time. Two modes (release versions / per-page history); navigate action ships in Phase 1.

Overview

<version-switcher> renders a small trigger button showing the current version of a page; clicking opens a picker popover listing every available version. Two modes auto-detected from the data shape:

  • Releases — entries have distinct URLs (/v1/page, /v2/page). Classic docs version selector.
  • History — entries share one URL but differ by date / author. Per-page edit-history list.

Override with data-mode="releases" or data-mode="history" if the data is ambiguous.

Phase 3: provenance integration

Meta-tag manifest fallback

If no inline data-versions and no data-src are provided, the component falls back to <meta name="vb:versions-manifest"> and fetches the URL listed there. The provenance build pipeline emits this tag from the page's versionsManifest frontmatter (per meta-tag-contract-v1).

Archived-version banner

Set data-banner to render a full-width warning banner above the trigger when the current version is archived AND a non-archived "latest" version exists. The banner uses role="region" + aria-live="polite" so screen-reader users hear the notice when it appears.

Mount inside <page-info>

Set data-page-info-target="ID" to render the version list as a section inside the named <page-info>'s expandable panel rather than as a standalone trigger. The standalone trigger is hidden in this mode — readers find versions inside the page-info panel alongside authorship + provenance.

Switch actions

Pick the action via data-action. Each action operates on the current page's versioned region — an element matched by data-versioned-region (defaults to [data-versioned], main).

ActionBehavior
navigate (default)Sets location.href to the picked entry's url. Cancellable via version-switcher:before-navigate.
swapFetches the picked URL, extracts its versioned region, and replaces the current versioned region in place. Updates <meta name="vb:version"> with the picked id. Uses document.startViewTransition for a crossfade when supported. Emits version-switcher:before-swap (cancellable) then version-switcher:swap.
diffFetches the picked URL, computes a line-level diff against the current versioned region, and mounts a <change-set> sibling containing the diff (use the change-set's tracking-view buttons to flip between final / original / both). data-diff-position="before|after" controls placement. Emits version-switcher:before-diff (cancellable) then version-switcher:diff.

When to use which primitive

Use thisWhen
<version-switcher>Switch between known versions of THIS page (releases or history snapshots).
<page-info>Show the current version + provenance + authors. Complementary — not the same. page-info answers "what version is this?"; version-switcher answers "what other versions exist?".
<time-index>Site-wide changelog timeline (releases of the whole project).
<change-set>Inline visual diff of authored markup (<ins>/<del>). version-switcher Phase 2's diff action will reuse this as its renderer.

Author surface

Inline the version list as JSON, either via the data-versions attribute or a <script type="application/json" data-versions> child.

Version entry shape

FieldTypeRequiredDescription
idstringyesStable identifier (semver, commit sha, "current", etc.).
labelstringnoDisplay label (defaults to id).
urlstringrecommendedURL to navigate to. Required for the navigate action.
datestring (ISO-8601)noRenders as relative time with absolute on hover.
authorstringnoUseful in history mode.
summarystringnoOne-line description (release-note excerpt or commit message).
archivedbooleannoRenders the "archived" badge and mutes the entry.
draftbooleannoRenders the "draft" badge.
currentbooleannoMarks the current entry. If absent, derived from a matching <meta name="vb:version"> or the first entry.
versionUrlstringnoOptional link out to a changelog anchor (matches the vb:version-url meta tag semantics).

Wiring the events

Accessibility

  • Trigger: aria-haspopup="dialog", aria-expanded tracks open state, aria-label describes the version (default "Version").
  • Picker: role="dialog" rendered by <pop-over> in the top layer; light-dismiss via Escape and outside click.
  • Each entry: a button with derived aria-label like v1.4, released 9 months ago, archived.
  • Current entry: aria-current="true" + visual highlight; focused first when the picker opens.
  • Keyboard inside the picker: ArrowUp / ArrowDown move between entries; Home / End jump to first / last; Enter / Space activate.
  • Focus return: after the picker closes, focus returns to the trigger.

Attributes

AttributeTypeDefaultDescription
data-versionsstring (JSON)Inline JSON array of version entries.
data-srcstring (URL)URL of a JSON manifest to fetch when no inline data is provided. Falls back to <meta name="vb:versions-manifest"> if neither is set.
data-modestringderivedreleases | history — override the auto-detected mode.
data-actionstringnavigatenavigate | swap | diff.
data-versioned-regionstring (CSS selector)[data-versioned], mainSelector for the swappable / diffable region in this page AND in the fetched response document.
data-diff-positionstringbeforebefore | after — where to mount the diff render relative to the versioned region.
data-bannerbooleanfalseRender an archived-version warning banner above the trigger when the current entry is archived AND a non-archived "latest" exists.
data-page-info-targetstring (ID)ID of a <page-info> to mount inside as a section in its expandable panel; the standalone trigger is hidden in this mode.
aria-labelstringVersionTrigger / picker label.

Events

EventBubblesDetail
version-switcher:openyes
version-switcher:closeyes
version-switcher:selectyes{ entry }
version-switcher:before-navigateyes (cancellable){ entry }
version-switcher:before-swapyes (cancellable){ entry }
version-switcher:swapyes{ entry, previousId }
version-switcher:before-diffyes (cancellable){ entry }
version-switcher:diffyes{ entry, previousId, diffElement, opCount }
version-switcher:erroryes{ message, entry?, error? }

JavaScript API

MemberDescription
versionsResolved version entries (read-only).
currentIdId of the current entry.
openPicker() / closePicker()Programmatic picker control.
switchTo(id)Programmatic selection — honors data-action.
refresh()Re-resolve the data source and re-render.

See also