Workspace Switcher
ProThe 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.
import { SvWorkspaceSwitcherComponent } from '@styloviz-pro/layout/workspace-switcher';Demo & usage
Basic usage
Usage example — open the gallery for the full interactive demo.
An interactive demo for this component lives in the gallery.
Open live demoMore examples
Commit or abandon a switch
Favourites and recent workspaces
Server-loaded list, and a collapsed rail
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
Changeevents to store what the user does.
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| workspaces | readonly WorkspaceSwitcherItem[] | [] | Every workspace the user can see, in display order within each organization. |
| currentId | string | null (two-way) | null | The id of the workspace the user is in now (two-way — the host commits a switch by setting it). |
| switchingTo | string | null (two-way) | null | The 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. |
| favoriteIds | readonly string[] (two-way) | [] | Ids of the user's favourite workspaces, in the order shown (two-way; the stars write it). |
| recentIds | readonly 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'`). |
| searchable | boolean | true | Show the search field. |
| favoritesEnabled | boolean | true | Show the star toggles and the Favourites section. |
| canCreate | boolean | true | Show the "Create workspace" action — hide it for users who may not create one. |
| canManage | boolean | true | Show the "Manage workspaces" action. |
| loading | boolean | false | The workspace list is loading — the panel shows a skeleton. |
| error | SvDataError | null | null | The workspace list failed to load — the panel shows the error and a retry. |
| compact | boolean | false | Show only the avatar on the trigger (for a collapsed sidebar). The name stays the accessible name. |
| surfaceId | string | null | null | Names this switcher in the shared navigation-analytics stream — a static name, never a record id. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| switchRequest | WorkspaceSwitchRequest | The user picked a workspace. Perform the switch, then set `currentId` (or clear `switchingTo` on failure). |
| favoriteChange | WorkspaceFavoriteChange | A favourite star was toggled (`favoriteIds` has already been updated). |
| create | void | "Create workspace" was chosen. |
| manage | void | "Manage workspaces" was chosen. |
| retry | void | The error state's Retry was pressed — reload the workspace list. |
| openChange | boolean | The panel opened (`true`) or closed (`false`). |
| currentIdChange | string | null | Emits the new `currentId` whenever it changes — the output half of `[(currentId)]`. |
| switchingToChange | string | null | Emits the new `switchingTo` whenever it changes — the output half of `[(switchingTo)]`. |
| favoriteIdsChange | readonly 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
Bound to the names this component actually exposes.
Host class
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.