Search documentation

Search pages, components, blocks, styles and colours.

Get started
Skip to content

Workspace Switcher

PreviousNext

Switches the organization or workspace an app shows. A menu for a few, a searchable dialog for many.

Workspace Switcher shows the current organization, team or workspace and switches to another. Pick the variant by how many a person usually has:

  • menu lists them in a dropdown, then Create and Manage.
  • command opens a searchable dialog. It searches names and descriptions, and lists its keys along the bottom. Add more groups as children, such as pending invitations.

While your app loads the workspace someone picked, pass its id as switchingTo and an overlay covers the wait.

Workspace Switcher is part of the Fabricator style.

Installation

bunx --bun fabricator-ui@latest add workspace-switcher

Usage

import { WorkspaceSwitcher } from "@/components/ui/workspace-switcher"
<SidebarHeader>
  <WorkspaceSwitcher
    workspaces={organizations}
    activeId={organization.id}
    onSelect={switchOrganization}
    onCreate={() => router.push("/new")}
    onManage={() => router.push("/settings/organizations")}
  />
</SidebarHeader>

Each workspace is { id, name, logo?, description? }. Without a logo, the name's first letter shows on the primary colour.

Sizes

  • size="row" fills the sidebar header with the logo, the name and the description. In the collapsed icon rail only the logo shows.
  • size="mark" is the logo alone, for a header row it shares with a User Menu mark and the sidebar toggle.

Switching

onSelect gets the id. Switching usually means loading data or navigating; set switchingTo until it's done:

const [switchingTo, setSwitchingTo] = React.useState<string | null>(null)
 
async function switchOrganization(id: string) {
  setSwitchingTo(id)
  await setActiveOrganization(id)
  router.push(`/${id}`)
  setSwitchingTo(null)
}

Inside an App Shell, ⌘O opens the switcher. Change it with shortcut, or pass null.

API Reference

WorkspaceSwitcher

PropTypeDefault
workspaces{ id, name, logo?, description? }[]-
activeIdstring-
onSelect(id: string) => void-
onCreate() => void-
onManage() => void-
createLabelstring"Create workspace"
manageLabelstring"Manage workspaces"
labelstring"Workspaces"
variant"menu" | "command""menu"
size"row" | "mark""row"
shortcutstring | null"mod+o"
switchingTostring | null-
childrenmenu items (menu) or command groups (command)-

Accessibility

  • The trigger is a button. The mark is named "Workspaces:" followed by the current name, and shows the name and shortcut in a tooltip.
  • Both variants mark the current workspace with a check, and its row's name ends with "(current)" for screen readers; the dialog has a title and a search field, and arrow keys move through the results. The key hints are hidden from screen readers.
  • The switching overlay is a status, so screen readers announce that the switch is under way.