Theme studio

Design a theme, preview it live, then export it. Saved in this browser.

Quick picks #10b981
Generated scale
50100200300400500600700800900
Some text is below AA

WorkspaceSwitcher

  • Stable
  • WCAG 2.2 evidence
  • RTL

Switches the active workspace from the top of a Sidebar: the current workspace's avatar, name and plan open a menu that lists every workspace. Built on the library Menu (React Aria MenuTrigger + Menu): the workspaces are a single-selection section, so the current one is announced as checked (menuitemradio), and extra actions such as "Create workspace" can follow in the same menu, which a listbox could not hold. Enter, Space and the arrow keys open it, arrows, Home/End and type-ahead move, Escape closes and returns focus (WCAG 2.1.1, 2.4.3, 4.1.2). The trigger's name is the visible text plus switchLabel (2.5.3). In the collapsed rail only the avatar shows and a tooltip gives the workspace name; the trigger stays at least 40 x 48 px (2.5.8). Consumer duties: what switching does (navigate, reload data) in onSelectionChange; wording of extra items.

import { WorkspaceSwitcher } from "@nexera-ui/react";
Loading example…
5
examples
30
props
6
live controls
1
platform
8
WCAG criteria
2
blocks use it

Try every prop. Copy the code.

Change the props and the code updates. Check light and dark, LTR and RTL, and phone width.

Loading…
children
variant
isCollapsed
defaultOpen
placement
isDisabled
Generated code
import { WorkspaceSwitcher } from "@nexera-ui/react";

<WorkspaceSwitcher />

Examples 4

The same examples as Storybook, rendered live. Open Code to copy one.

Menu open with actions

The menu open: workspaces as single-choice items, then extra actions after a divider.

Loading example…

Variants and rail

Figma Variant=Light and Collapsed=True (avatar only; focus or hover it for the name).

Loading example…

Long name

Long workspace names wrap.

Loading example…

Right to left

Right to left.

Loading example…

Props 30

Press "Try it" on a card to load that prop into the playground.

30 props shown

workspaces*Nexera
readonly Workspace[]

The workspaces, listed in the menu as single-choice items (menuitemradio); the chosen one fills the trigger.

Default –
selectedKeyNexera
Key

Key of the current workspace (controlled). Use with onSelectionChange.

Default –
defaultSelectedKeyNexera
Key

Key of the current workspace on first render (uncontrolled).

Default the first workspace
onSelectionChangeNexera
(key: Key) => void

Called with the key of the workspace the user switches to.

Default –
childrenNexera
ReactNode

Extra menu items after a divider, for example "Create workspace" or "Workspace settings" (MenuItem elements). Their activation is reported by onAction.

Default –
onActionNexera
(key: Key) => void

Called with the id of an extra item (from children) the user activates.

Default –
switchLabelNexera
string

Visually hidden text added to the trigger's accessible name after the visible workspace and plan, so the purpose is announced ("Acme Pakistan Business plan Switch workspace"). Translate it.

Default Switch workspace
variantNexera
"brand" | "light"

Colour scheme.

Default the enclosing Sidebar's variant, else "brand"
isCollapsedNexera
boolean

Show only the avatar; the workspace name moves to a tooltip.

Default the enclosing Sidebar's collapsed state, else false
isOpenNexera
boolean

Whether the menu is open (controlled). Use with onOpenChange.

Default –
defaultOpenNexera
boolean

Whether the menu is open on first render (uncontrolled).

Default false
onOpenChangeNexera
(isOpen: boolean) => void

Called when the menu opens or closes.

Default –
placementNexera
"bottom" | "bottom left" | "bottom right" | "bottom start" | "bottom end" | "top" | "top left" | "top right" | "top start" | "top end" | "left" | "left top" | "left bottom" | "start" | "start top" | "start bottom" | "right" | "right top" | "right bottom" | "end" | "end top" | "end bottom"

Where the menu opens. It flips to stay in the viewport.

Default "bottom start", or "end top" when collapsed
classNameNexera
string

Extra classes for the trigger, merged last so they win over the defaults.

Default –
styleNexera
CSSProperties

Inline style for the trigger.

Default –
isDisabledReact Aria
boolean

Whether the button is disabled.

Default –
onPressReact Aria
(e: PressEvent) => void

Handler that is called when the press is released over the target.

Default –
onPressStartReact Aria
(e: PressEvent) => void

Handler that is called when a press interaction starts.

Default –
onPressEndReact Aria
(e: PressEvent) => void

Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target.

Default –
onPressChangeReact Aria
(isPressed: boolean) => void

Handler that is called when the press state changes.

Default –
onPressUpReact Aria
(e: PressEvent) => void

Handler that is called when a press is released over the target, regardless of whether it started on the target or not.

Default –
autoFocusReact Aria
boolean

Whether the element should receive focus on render.

Default –
typeReact Aria
"button" | "submit" | "reset"

The behavior of the button when used in an HTML form.

Default 'button'
formReact Aria
string

The <form> element to associate the button with. The value of this attribute must be the id of a <form> in the same document. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button#form).

Default –
nameReact Aria
string

Submitted as a pair with the button's value as part of the form data.

Default –
valueReact Aria
string

The value associated with the button's name when it's submitted with the form data.

Default –
idReact Aria
string

The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id).

Default –
aria-labelReact Aria
string

Defines a string value that labels the current element.

Default –
aria-labelledbyReact Aria
string

Identifies the element (or elements) that labels the current element.

Default –
aria-describedbyReact Aria
string

Identifies the element (or elements) that describes the object.

Default –

* Required. React Aria props shown are the ones most apps use; the component accepts the rest of its React Aria props too.

Accessible by default.

Built on React Aria, and covered by the WCAG 2.2 evidence generated on every build.

WCAG 2.2 evidence

6 direct · 2 supporting
  • 1.3.1Info and RelationshipsLevel A · tested directly
  • 1.4.12Text SpacingLevel AA · supporting test
  • 1.4.13Content on Hover or FocusLevel AA · tested directly
  • 2.1.1KeyboardLevel A · tested directly
  • 2.4.3Focus OrderLevel A · tested directly
  • 2.4.7Focus VisibleLevel AA · supporting test
  • 2.5.3Label in NameLevel A · tested directly
  • 4.1.2Name, Role, ValueLevel A · tested directly

Fits any width.

Nexera components respond to the space they are given. Drag the corner of the frame, or pick a width.

0 px · drag the corner

Styling hooks

Pass className to add Tailwind classes (merged last). State is exposed as data attributes, so you can style it with variants like data-pressed:.

  • data-disabled
  • data-hovered
  • data-pressed
Usage
<WorkspaceSwitcher className="data-disabled:opacity-90 shadow-sm" />

Used in blocks

Related components