Move between teams or workspaces from the top of an app. The trigger shows the team you are in with its plan and size; the menu shows the rest with your role, finds one by name once the list grows, takes Cmd or Ctrl + 1 to 9, accepts an invite and creates a team. It folds to the mark alone in an icon rail.
On this page
- Top of an app sidebar
- Workspace picker
- Icon rail
- Accepting an invite
- Org switch in a header
Examples
Many teams, with search
Past six teams the menu opens with focus in a search field. Type to narrow by name, plan or role; the arrows still move through the rows and Enter picks. Esc clears the search first, then closes. Change the cut with searchThreshold.
In an icon rail
collapsed keeps only the mark. The team's name and plan become the trigger's accessible name and its tooltip, and the menu opens to the right of the rail.
With a pending invite
Invitations sit under your teams with who sent them and the role offered. Enter or a click on the row accepts; a promise from onAcceptInvite keeps the menu open with a spinner until it settles. Here the team joins the list and becomes current.
In the sidebar
The Sidebar block's SidebarSwitcher is this component: it takes workspaces and the same props, follows the rail, and leaves search and the shortcuts off unless you pass searchThreshold and shortcuts.
Installation
npx knowns-ui@latest add team-switcherPaste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install Team switcher from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/team-switcher
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add team-switcher
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/use-floating.ts
- components/ui/knowns/tooltip.tsx
- components/ui/knowns/tooltip-utils.ts
- components/ui/knowns/avatar.tsx
- components/ui/knowns/menu.tsx
- components/ui/knowns/spinner.tsx
- components/ui/knowns/team-switcher/team-switcher.tsx
- components/ui/knowns/team-switcher/team-switcher-utils.ts
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/team-switcher, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "team-switcher" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.Props
- teams
Team[]- { id, name, plan?, role?, members?, description?, src?, icon?, swatch? }. plan and members make the trigger's second line, role and plan the row's; description is used when there are none.
- value
string- Id of the current team. It gets the check, and the menu opens on it.
- onChange
(id) => void- A team was picked, by click, Enter or its shortcut.
- onCreate
() => void- Shows the Create row at the bottom.
- createLabel
string- Default
"Create team" - Text of the Create row.
- invites
TeamInvite[]- { id, team, invitedBy?, role? }. Listed under Invitations when onAcceptInvite is set.
- onAcceptInvite
(id) => unknown- Accept an invite. A promise keeps the menu open with a spinner until it settles.
- searchThreshold
number|false- Default
6 - Show the search field when there are more teams than this.
- searchPlaceholder
string- Default
"Find a team" - Placeholder of the search field.
- shortcuts
boolean- Default
true - Cmd (Mac) or Ctrl + 1..9 pick the first nine teams from anywhere on the page, and the menu shows the keys. Turn it off when two switchers share a page.
- collapsed
boolean- Default
false - Mark only, for a rail, with the name in a tooltip and the accessible name.
- expanded
boolean- Default
false - The list open in the flow as a radiogroup card, instead of a menu.
- label
string- Default
"Switch team" - Accessible name of the menu, and part of the collapsed trigger's name.
- groupLabel / invitesLabel
string- Default
"Teams" / "Invitations" - Small labels over the two groups.
- align / side
"start"|"end" / "auto"|"bottom"|"top"|"right"- Default
"start" / "auto" - Where the menu opens. Collapsed defaults to the right.
- width
number- Default
288 - Menu width in px, never wider than the screen less 16px.
- open / onOpenChange
boolean / (open) => void- Control the menu from outside.
- textWrap
ComponentType- Wraps the trigger's text and chevron, for a host that animates them itself (the sidebar's rail).
- className
string- Classes on the trigger.
| Prop | Type | Default | Description |
|---|---|---|---|
| teams | Team[] | - | { id, name, plan?, role?, members?, description?, src?, icon?, swatch? }. plan and members make the trigger's second line, role and plan the row's; description is used when there are none. |
| value | string | - | Id of the current team. It gets the check, and the menu opens on it. |
| onChange | (id) => void | - | A team was picked, by click, Enter or its shortcut. |
| onCreate | () => void | - | Shows the Create row at the bottom. |
| createLabel | string | "Create team" | Text of the Create row. |
| invites | TeamInvite[] | - | { id, team, invitedBy?, role? }. Listed under Invitations when onAcceptInvite is set. |
| onAcceptInvite | (id) => unknown | - | Accept an invite. A promise keeps the menu open with a spinner until it settles. |
| searchThreshold | number | false | 6 | Show the search field when there are more teams than this. |
| searchPlaceholder | string | "Find a team" | Placeholder of the search field. |
| shortcuts | boolean | true | Cmd (Mac) or Ctrl + 1..9 pick the first nine teams from anywhere on the page, and the menu shows the keys. Turn it off when two switchers share a page. |
| collapsed | boolean | false | Mark only, for a rail, with the name in a tooltip and the accessible name. |
| expanded | boolean | false | The list open in the flow as a radiogroup card, instead of a menu. |
| label | string | "Switch team" | Accessible name of the menu, and part of the collapsed trigger's name. |
| groupLabel / invitesLabel | string | "Teams" / "Invitations" | Small labels over the two groups. |
| align / side | "start" | "end" / "auto" | "bottom" | "top" | "right" | "start" / "auto" | Where the menu opens. Collapsed defaults to the right. |
| width | number | 288 | Menu width in px, never wider than the screen less 16px. |
| open / onOpenChange | boolean / (open) => void | - | Control the menu from outside. |
| textWrap | ComponentType | - | Wraps the trigger's text and chevron, for a host that animates them itself (the sidebar's rail). |
| className | string | - | Classes on the trigger. |
Accessibility
- The trigger is a button with aria-haspopup and aria-expanded. Down or Up opens the menu, which lands on the current team.
- Without search the list is a menu of menuitemradio rows, with the current team checked. With search the field is a combobox over a listbox, and the current team carries aria-current.
- Focus stays on the list or the field and the active row is aria-activedescendant: arrows, Home, End, type-ahead by the first letters, Enter to pick, Esc to clear the search and then close, Tab to leave. Focus goes back to the trigger.
- Each row with a shortcut names it in aria-keyshortcuts. An invite row reads as "Accept invite to Tidewater Analytics as Editor", and joining is announced while it runs.
- Collapsed, the trigger's name is the team, its plan and size, and "Switch team".
What it handles
- 01Shows the current team as a trigger: its mark, name, plan and member count, and a chevron.
- 02Shows every team with its mark, your role and its plan, and a check on the one you are in.
- 03Opens with a search field once there are more than six teams, and keeps Invitations and Create in place while you filter.
- 04Switches with Cmd or Ctrl + 1 to 9 from anywhere on the page, and shows each key in the menu.
- 05Shows pending invitations with an Accept button, and keeps the menu open with a spinner while your call runs.
- 06Folds to the mark alone for an icon rail, with the name in a tooltip and in the trigger's accessible name.
States
- First render
- Nothing moves
- none
- Open and close
- The menu fades in, and out a little faster
- 120ms in, 80ms out, ease out
- Move through rows
- The highlight jumps to the row, no glide
- none
- Team switched
- The trigger's mark pops in and its name rises 4px into place; with the menu open, the check pops on the new row
- 180ms, spring for the pops, ease out for the text
- Accepting an invite
- A spinner turns on the Accept button until your call settles
- spinner
- Invite accepted
- The button turns green, a check pops from small past its size and Joined rises in; the new team's row eases 6px into the list, and a beat later the invite row folds away and the highlight moves to the new team
- 420ms check, then 120ms fold; the rise is 180ms; about 600ms in all
- Rail tooltip
- Fades in and out like the menu
- 120ms, ease out
- Hover
- The trigger's fill darkens a step
- 120ms, ease out
- Reduced motion
- Everything appears at once
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | Nothing moves | none |
| Open and close | The menu fades in, and out a little faster | 120ms in, 80ms out, ease out |
| Move through rows | The highlight jumps to the row, no glide | none |
| Team switched | The trigger's mark pops in and its name rises 4px into place; with the menu open, the check pops on the new row | 180ms, spring for the pops, ease out for the text |
| Accepting an invite | A spinner turns on the Accept button until your call settles | spinner |
| Invite accepted | The button turns green, a check pops from small past its size and Joined rises in; the new team's row eases 6px into the list, and a beat later the invite row folds away and the highlight moves to the new team | 420ms check, then 120ms fold; the rise is 180ms; about 600ms in all |
| Rail tooltip | Fades in and out like the menu | 120ms, ease out |
| Hover | The trigger's fill darkens a step | 120ms, ease out |
| Reduced motion | Everything appears at once | 0ms |
Works with
When to use
When to use
- The top of an app sidebar or header when people work in several teams or workspaces: which one they are in, its plan and size, and a quick way to the others.
- An app where people belong to many orgs: search by name, Cmd or Ctrl + 1 to 9, and pending invites accepted in place.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Team Switcher to my app and wire it to my own data.
- I need the top of an app sidebar or header when people work in several teams or workspaces: which one they are in, its plan and size, and a quick way to the others. Set that up with the Knowns UI Team Switcher.
- Which Team Switcher props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "team-switcher" }) and search_docs({ query: "team switcher" }).