Workspace Switcher

Pro

The current workspace of a multi-tenant dashboard and the one place it changes. A body-portalled panel lists favourite and recent workspaces and every workspace grouped by organization, with a search across all of them, a favourite star per row, locked workspaces that say why, and Create / Manage actions. The switch itself is an explicit state: a pick sets `switchingTo`, the trigger goes busy and announces it, and the host commits by setting `currentId` — so the old tenant's data never stays on screen under the new tenant's name.

</>sv-workspace-switcher workspace switchertenant switcherorganization switcheraccount switchernavigationmulti-tenant
import { SvWorkspaceSwitcherComponent } from '@styloviz-pro/layout/workspace-switcher';

Demo & usage

Basic usage

Pro

Usage example — open the gallery for the full interactive demo.

Pro

An interactive demo for this component lives in the gallery.

Open live demo

More examples

Commit or abandon a switch

Pro

Favourites and recent workspaces

Pro

Server-loaded list, and a collapsed rail

Pro

When to use

  • Job: context — a multi-tenant dashboard where the same screens show a different organization, project or account depending on the workspace.
  • The user belongs to several workspaces, across organizations, and switches often enough to want favourites and recents.
  • For moving between pages of one workspace, use Sidebar Nav or Mega Menu; for a one-off choice in a form, use Select.

Async states

  • loading
  • error
  • retry

Item identity & owned state

Restorable state
  • favoriteIds

Bind these to put a saved view back — the open sections, the hidden columns, the selected rows — and read their Change events to store what the user does.

Inputs

NameTypeDefaultDescription
workspacesreadonly WorkspaceSwitcherItem[][]Every workspace the user can see, in display order within each organization.
currentIdstring | null (two-way)nullThe id of the workspace the user is in now (two-way — the host commits a switch by setting it).
switchingTostring | null (two-way)nullThe workspace being switched to while the host loads it (two-way). Set by a pick; the host clears it on failure, and it clears itself when `currentId` arrives at it. Blank stale views while it is non-null.
favoriteIdsreadonly string[] (two-way)[]Ids of the user's favourite workspaces, in the order shown (two-way; the stars write it).
recentIdsreadonly string[][]Ids of recently visited workspaces, most recent first — the first three (other than the current one) are shown.
groupBy'org' | 'none''org'Group the full list by `org` (`'org'`) or show one flat list (`'none'`).
searchablebooleantrueShow the search field.
favoritesEnabledbooleantrueShow the star toggles and the Favourites section.
canCreatebooleantrueShow the "Create workspace" action — hide it for users who may not create one.
canManagebooleantrueShow the "Manage workspaces" action.
loadingbooleanfalseThe workspace list is loading — the panel shows a skeleton.
errorSvDataError | nullnullThe workspace list failed to load — the panel shows the error and a retry.
compactbooleanfalseShow only the avatar on the trigger (for a collapsed sidebar). The name stays the accessible name.
surfaceIdstring | nullnullNames this switcher in the shared navigation-analytics stream — a static name, never a record id.

Outputs

EventPayload typeDescription
switchRequestWorkspaceSwitchRequestThe user picked a workspace. Perform the switch, then set `currentId` (or clear `switchingTo` on failure).
favoriteChangeWorkspaceFavoriteChangeA favourite star was toggled (`favoriteIds` has already been updated).
createvoid"Create workspace" was chosen.
managevoid"Manage workspaces" was chosen.
retryvoidThe error state's Retry was pressed — reload the workspace list.
openChangebooleanThe panel opened (`true`) or closed (`false`).
currentIdChangestring | nullEmits the new `currentId` whenever it changes — the output half of `[(currentId)]`.
switchingToChangestring | nullEmits the new `switchingTo` whenever it changes — the output half of `[(switchingTo)]`.
favoriteIdsChangereadonly string[]Emits the new `favoriteIds` whenever it changes — the output half of `[(favoriteIds)]`.

Wire it to your API

This component is headless about transport: it renders what you give it and reports what the user asks for. Nothing below requires @styloviz/data — drive it from whatever you already use.

Template

Pro

Bound to the names this component actually exposes.

Host class

Pro

Drive the three async inputs from your own fetch.

  • This component does not emit a query, so it renders what you give it. Call `load()` on your own trigger and bind `workspaces`, `loading` and `error`.
  • Normalize failures with `toSvDataError()` from `@styloviz/core`. It derives `retryable` from the status, so a 404 does not get a "Try again" button that can only fail again.

Full walkthrough: Connecting to a backend.

Customization & theming

  • `groupBy` `org` (the default) or `none`; `searchable`, `favoritesEnabled`, `canCreate`, `canManage`.
  • Per-workspace `initials`, `tone`, `role`, `description` and `badge`.
  • `compact` shows only the avatar, for a collapsed sidebar rail.
  • `loading`, `error` and `(retry)` for a list loaded from a server; an empty list offers Create.
  • `surfaceId` names it in the navigation-analytics stream (`provideSvNavTelemetry()`).

Best practices

  • Do: Blank or skeleton tenant data while `switchingTo` is set (or `[data-sv-switching]` is on the element) — the old workspace's numbers under the new name is the failure this component exists to prevent.
  • Do: End every switch: set `currentId` to commit, or clear `switchingTo` to abandon. Both are announced.
  • Do: Keep workspaces a user can see but not enter in the list with `disabled` and a `disabledReason` — a hidden workspace leaves them unable to ask for access.
  • Don't: Don't change `currentId` before the new workspace's data has loaded.
  • Tip: Hide Create with `[canCreate]="false"` for users who may not create one, rather than letting the action fail.

Accessibility

  • The trigger is a button with `aria-haspopup="dialog"` and `aria-expanded`; its accessible name says which workspace is current and that it switches.
  • The panel is a labelled dialog: focus goes to the search field, ↑/↓ move through the rows (locked rows are skipped), Home/End jump, Escape closes and returns focus to the trigger, Tab leaves.
  • Rows are grouped (`role="group"`, labelled by their heading); the current row carries `aria-current`; a locked row is `aria-disabled` and described by its reason.
  • Favourite stars are toggle buttons (`aria-pressed`) with a per-workspace name; every target is at least 32 px.
  • Switching, switched and a failed switch are announced through the shared live region, and the element is `aria-busy` while a switch is in flight.

Feedback on Workspace Switcher

Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.

Loads giscus.app and GitHub — nothing is fetched until you click.