Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Account Switcher Command Menu Block for React

An agency billing portal's account switcher as a command menu shown open under the account chip: four accounts with initials, role and plan, a tick on the current one, the keys 1 to 4 to switch straight to an account, and the chip and status line that follow the choice.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Move between the accounts a person works in with this account switcher command menu for React with Base UI. It opens from the Invoices page of Brieflane, an agency billing portal, whose header holds an outline field with its ⌘ K cap, and the page is drawn under a soft scrim inside a hairline frame with a plus mark on each corner: a bar that starts with the account chip, and an invoices table made of shapes. The menu hangs from the chip and is the catalog Command. It lists four accounts under Accounts, each with an initials Avatar, its name, your role in it as a word, Owner, Editor or Viewer, and its plan, and a tick on the one you are in. Under Manage sit "Add account…" and "Sign out of all". While the search box is empty the keys 1 to 4 switch straight to the account at that place; once you type, digits are text. Choosing an account moves the chip and the status line says so, "Switched to Northpier Studio. In this demo only."; nothing signs in or out. For preview the menu is drawn open in place when the page loads; the field, or Ctrl or ⌘ K while focus is in the block, opens the real command dialog with the same rows and query. For agencies, accountants, marketplaces and any product where one login reaches several organisations.

FAQ

Why is the menu already open, and what do I keep?

So you can see it without a click. On load the menu is the Command drawn inline under the drawn chip, in a plain shell that is not modal, so nothing is trapped, hidden or focused and the page around the preview keeps working. The header's field opens the real command dialog, modal, with its focus trap, Escape and focus return, and the inline copy stays closed until a reload. Both show the same Palette and share the block's state, so what you typed in the copy is in the real dialog. In your app keep the dialog and drop the copy: the "in-place" state, the scrim with its shell and the Escape and blur effects.

How do the number keys work?

A capture listener on the menu reads event.code (Digit1 to Digit4, or the keypad) while the search box is empty and focus is inside the menu, and switches to the account at that place. It reads the physical key, so a layout that needs Shift for its digits still works. Once the box has any text the digits are ordinary characters, and the caps beside the rows go away so the screen never promises a key that would not work. Alt, Ctrl, Cmd and Shift with a digit are left alone.

What stays local, and how do I wire it?

Everything. Choosing an account changes the chip and the status line and nothing else: no session changes, no request goes out, "Add account…" opens nothing and "Sign out of all" signs nobody out. In your app the choice would change the session (a cookie, a token or a route) and refetch the page; keep choose as the one place that happens, and keep the status line, which is the one polite live region.

Is it accessible from the keyboard?

Yes. Type to search, the arrow keys move, Enter switches to the highlighted account and Escape closes the menu and puts focus on the field; Ctrl or ⌘ K opens the dialog while focus is inside the block, and only then. The current account's row says so for screen readers as well as with the tick. The rows are options of a cmdk listbox; the block turns off its own fuzzy filter and lists the rows itself.

How does it look on a phone?

The copy shown on load docks to the top of the page at full width under the bar, so the keyboard does not cover the foot; the key hints go and the count stays. The digit keys need a hardware keyboard, so rows stay the way in. The real dialog keeps the Command dialog's own phone layout.

  • Pro

    A support console's view-as switcher as a command menu shown open under the avatar: You and Teammates with initials, role and queue size, a read-only banner with an Exit button, and a ticket list that shows only that person's queue.

  • Pro

    A knowledge base's workspace switcher as a command menu shown open under the switcher at the head of the sidebar: member counts, a star that pins a workspace live into a Pinned group, and a Create row that adds a new workspace from what you typed and switches to it.

  • Pro

    Account Menu Navbar

    Accounts and scopes

    An app bar with an account button behind a split divider that opens a menu: an identity header with plan badge and storage bar, a Switch account radio list, and Profile, Settings, Billing and Sign out.

  • Pro

    The people who can act on an account as a matrix: a row for each delegate with a box for each of four scopes, pending invitations with Resend, an invitation form whose role ticks the scopes, and Undo.

  • Pro

    Workspace Switcher Navbar

    Accounts and scopes

    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.

  • Pro

    Basic Command Menu

    Search everything

    A team workspace's home page with its command menu shown open: eleven pages in three groups, a shortcut on the five most used, matches marked, an empty state that says what to try and a foot with the key hints and a spoken count.