shadcn.io is not affiliated with official shadcn/ui
Workspace Switcher Navbar Block for React
An app bar whose switcher button opens a searchable list of workspaces: recent ones first with number keys, a plan badge on every row, a check on the current one and a Create workspace button in the foot.
Installation
Overview
A workspace switcher for React with Base UI, in the app bar of a team wiki and chat called Hivespace. The wordmark leads, a solid divider that meets the top rule sets off the switcher button (a tile with two letters and the workspace's name), Pages, Chat and Tasks follow, and a Shine Button closes the row. The button opens a searchable list over the page: three recent workspaces first, each with a number key that picks it, then the rest, every row with its plan as a badge and a check on the current one, and a "Create workspace" button in the foot. Choosing a workspace rewrites the button, says so in a polite line, closes the list and returns focus to the button. On a phone the list opens as a drawer from the bottom and the links move into a sheet from the top. It's built from Popover, Command, Drawer, Sheet, Badge, Guides, Shine Button and Button, with your theme's tokens for every colour. For apps whose users belong to more workspaces than a menu of six can hold.
FAQ
How do I change the workspaces and the plans?
Edit RECENT, OTHERS and CREATED at the top of the file: an id, a name, a plan and the two letters on the tile. The list, the search, the number keys and the button's width are all built from them, so adding an object is enough. The workspaces and their plans are made up for the demo. In an app, replace settle with your router's or session's workspace change.
What does Create workspace do?
It adds the next entry of CREATED to the "All workspaces" group, switches to it and says so ("Created Untitled space 1 and switched to it. Nothing is saved in this demo."). Three can be added; after that the button says "Workspace limit reached" and does nothing. Nothing is stored or sent: wire create to your own flow.
How do the number keys work?
While the search field is empty, pressing 1, 2 or 3 picks the matching recent workspace and closes the list. As soon as you type, the digits are text again and the number hints disappear. The modified keys (Ctrl, Alt, Command) are left alone.
How does it work with a keyboard and a screen reader?
The links sit in a nav named Main. The switcher button is named "Workspace: Duskmere Studio", says whether the list is open and which list it controls, and opens it on Enter or Space with focus in the search field. Typing narrows the list by name or plan (accents ignored). The current row says "current workspace" as well as showing a check, and the number hints are read as "key 1". Escape closes the list and returns focus to the button, and so does choosing a row.
The list is a command built on cmdk: the first match is highlighted as you type, the arrow keys move through the rows and Enter chooses.
How does it work on a phone?
Below the md breakpoint the bar shows the wordmark's icon, the switcher (its name truncates) and a menu button; nothing wraps at 320 pixels. The switcher opens a drawer from the bottom with the same list and the same foot; the links and the Invite action move into a sheet from the top. Escape, the close button or choosing a row closes them and focus goes back to the button that opened them.
Does it work right to left?
Yes. The bar mirrors, the divider stays between the first two cells, the list opens under the button's start edge, and rows, checks and chevrons follow the direction. The wordmark is artwork and keeps its direction.
Wrap the block in your direction provider (the catalog's DirectionProvider) so the popover and the drawer follow the page.
Related
- Pro
Multi-Tenant Navbar
Accounts and scopesAn app bar with two chained scopes, organization then project: choosing an organization rewrites the project list, and a role badge sits beside the organization's name.
- Pro
Environment Switcher Navbar
Accounts and scopesAn app bar with a Production, Staging and Development segment control that shows the environment's base URL with a copy button and asks for confirmation before switching to Production.
- Pro
Split Layout Navbar
Cells and splitsAn app bar split by a solid divider that meets the top rule: navigation at the start, and at the end a help link and an avatar whose menu sets your presence (Active, Away, Do not disturb) and recolours its dot.
- Pro
Language Switcher Navbar
Accounts and scopesA navbar whose language button opens a searchable list of twelve languages in their own scripts; choosing one rewrites the bar's links and action, and choosing Arabic flips the whole bar right to left.
- Pro
Workspace Top Bar Banner
Utility barsA top bar for a team workspace manager that says which workspace you are in, with your role as a badge and a Switch menu of workspaces behind a divider.
- Pro
SaaS Marketing Navbar
Mega menusA one-bar marketing navbar for a product roadmap tool: a wordmark, a Product menu of four areas with icons and one-line descriptions, plain links with the current page marked, Sign in and a Shine Button, and a sheet with the same links on phones.