Skip to content

Looking for Clerk’s docs? Head to clerk.com/docs (opens in a new tab)

Mosaic
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

GuidancePractice
DoPut Switcher.Trigger and Switcher.Popup inside one Switcher.Root, and label the popup with aria-label.
DoWrap rows in a Switcher.Group, and split groups with a Switcher.Separator.
DoPass render to Switcher.Item to make a row a button or link. It then takes the hover and press styles.
Don’tExpect 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.

PropTypeDescription
openbooleanThe controlled open state.
defaultOpenbooleanThe initial open state when uncontrolled.Default: false
onOpenChange(open: boolean) => voidCalled when the popup opens or closes.
placementPlacementWhere the popup sits against the trigger.Default: 'bottom-start'
sideOffsetnumberThe gap between the trigger and the popup.Default: 4
alignOffsetnumberShifts 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

PropTypeDescription
avatarReactNodeThe lead's mark, such as a Switcher.BadgedAvatar.
namestringThe lead's name. Leave it out for the avatar-only trigger.
badgestringA plan or status label beside the name.
badgeIdstringSet 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

PropTypeDescription
aria-labelstringNames the popup.
renderBrandingbooleanShows 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

PropTypeDescription
avatarReactNodeThe leading mark.
titlestringThe name, on one line.
descriptionstringA second line, such as an email address.

Switcher.Avatar

A decorative avatar with initials as its fallback, hidden from assistive tech.

Slot: cl-avatar

PropTypeDescription
namestringThe name the initials come from.
imageUrlstringThe 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

PropTypeDescription
namestringThe lead name.
imageUrlstringThe 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

PropTypeDescription
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

TSX
<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>