On this page
Switcher
The account and organization switcher. Switcher.Root holds the open state, Switcher.Trigger opens it, and Switcher.Popup positions a Card holding Switcher.Header, then Switcher.Groups of Switcher.Items split by Switcher.Separators. UserButton, OrganizationSwitcher and Switcher from @clerk/mosaic compose these parts with Clerk's session and organization state. The parts carry cl-switcher-* classes; inside UserButton and OrganizationSwitcher the same parts carry cl-user-button-* and cl-organization-switcher-*. Switcher.Avatar carries cl-avatar.
Use for
- an account or organization switcher composed from its parts
Practices
| Guidance | Practice |
|---|---|
| Do | Put Switcher.Trigger and Switcher.Popup inside one Switcher.Root, and label the popup with aria-label. |
| Do | Wrap rows in a Switcher.Group, and split groups with a Switcher.Separator. |
| Do | Pass render to Switcher.Item to make a row a button or link. It then takes the hover and press styles. |
| Don’t | Expect the parts to read Clerk. They render the props they are given; UserButton and OrganizationSwitcher connect them to Clerk. |
API reference
Switcher.Root
Holds the open state. Renders no element of its own.
| Prop | Type | Description |
|---|---|---|
open | boolean | The controlled open state. |
defaultOpen | boolean | The initial open state when uncontrolled.Default: false |
onOpenChange | (open: boolean) => void | Called when the popup opens or closes. |
placement | Placement | Where the popup sits against the trigger.Default: 'bottom-start' |
sideOffset | number | The gap between the trigger and the popup.Default: 4 |
alignOffset | number | Shifts the popup along the trigger edge.Default: 0 |
Switcher.Trigger
Opens the popup. With a name it shows the name, the badge and a caret; without one, the avatar alone.
Slot: cl-switcher-trigger
| Prop | Type | Description |
|---|---|---|
avatar | ReactNode | The lead's mark, such as a Switcher.BadgedAvatar. |
name | string | The lead's name. Leave it out for the avatar-only trigger. |
badge | string | A plan or status label beside the name. |
badgeId | string | Set as data-badge-id on the badge. |
shape | 'circle' | 'square' | Rounds the avatar-only trigger to match a circular avatar.Default: 'square' |
variant | 'full' | 'condensed' | Which mark the trigger carries, set as data-variant: full for a Switcher.BadgedAvatar, condensed for a Switcher.Avatar.Default: 'condensed' |
Switcher.Popup
The floating popup: portals, positions against the trigger, and paints a Card holding its children. A dialog named by aria-label.
Slot: cl-switcher-popover
| Prop | Type | Description |
|---|---|---|
aria-label | string | Names the popup. |
renderBranding | boolean | Shows Clerk branding at the foot of the card.Default: true |
Switcher.Header
The popover's header: the lead's avatar, its name and a description.
Slot: cl-switcher-header
| Prop | Type | Description |
|---|---|---|
avatar | ReactNode | The leading mark. |
title | string | The name, on one line. |
description | string | A second line, such as an email address. |
Switcher.Avatar
A decorative avatar with initials as its fallback, hidden from assistive tech.
Slot: cl-avatar
| Prop | Type | Description |
|---|---|---|
name | string | The name the initials come from. |
imageUrl | string | The image. |
shape | 'circle' | 'square' | Circle for a person, square for an organization. |
size | 'xs' | 'sm' | 'md' | 'lg' | 'fit' | Box size. fit fills the parent. |
Switcher.BadgedAvatar
An organization's square avatar with a person's round avatar cut into its corner.
Slot: cl-switcher-avatar
| Prop | Type | Description |
|---|---|---|
name | string | The lead name. |
imageUrl | string | The lead image. |
badge | { name: string; imageUrl?: string } | The person in the corner. |
size | 'sm' | 'md' | Box size. |
Switcher.Group
A run of rows inside the popover.
Slot: cl-switcher-group
Switcher.Separator
A rule between groups.
Slot: cl-switcher-separator
Switcher.Item
One row. Renders a div, or the render element, which makes it interactive.
Slot: cl-switcher-item
Switcher.ItemMedia
The row's leading avatar or icon.
Slot: cl-switcher-item-media
Switcher.ItemContent
The row's text column.
Slot: cl-switcher-item-content
Switcher.ItemLabel
The row's name, on one line.
Slot: cl-switcher-item-label
| Prop | Type | Description |
|---|---|---|
variant | 'default' | 'interactive' | default names the row's subject. interactive takes the row's color, for rows such as Sign out.Default: 'default' |
Switcher.ItemDescription
A second line under the label.
Slot: cl-switcher-item-description
Switcher.ItemTrailing
Content at the end of the row, such as a checkmark or a badge.
Slot: cl-switcher-item-trailing
Examples
A trigger and its popup
<Switcher.Root>
<Switcher.Trigger
aria-label='Open account menu'
avatar={<Switcher.BadgedAvatar name='Acme' badge={{ name: 'Alice Smith' }} size='sm' />}
name='Acme'
badge='Pro'
variant='full'
/>
<Switcher.Popup aria-label='Account menu'>
<Switcher.Header
avatar={<Switcher.BadgedAvatar name='Acme' badge={{ name: 'Alice Smith' }} size='md' />}
title='Acme'
description='alice@example.com'
/>
<Switcher.Separator />
<Switcher.Group>
<Switcher.Item render={<button type='button' />}>
<Switcher.ItemMedia>
<Switcher.Avatar name='Globex' shape='square' size='sm' />
</Switcher.ItemMedia>
<Switcher.ItemContent>
<Switcher.ItemLabel>Globex</Switcher.ItemLabel>
<Switcher.ItemDescription>Member</Switcher.ItemDescription>
</Switcher.ItemContent>
<Switcher.ItemTrailing>…</Switcher.ItemTrailing>
</Switcher.Item>
</Switcher.Group>
</Switcher.Popup>
</Switcher.Root>