Skip to main content

RoleSwitcher

ComplexAccess<co-role-pill>

RoleSwitcher is the "Viewing as" control in the top bar; it is the same component as RolePill, exported under the composite name.

import { RoleSwitcher } from 'health-components';

Examples​

In Top Bar​

Storybook

Usage​

<RoleSwitcher role={role} roles={ROLES} onChange={r => setPreviewRole(r)} />

When to use​

  • Previewing the app as another role.

When not to use​

  • Changing someone's real role.

Variants and states​

VariantWhat it is
closed / openSee RolePill.
on navyInside TopBar variant classic it turns white.

Accessibility​

  • As RolePill.

Do and don't​

  • Do: Reload the screen in the chosen role and show the lock banners that role gets.
  • Don't: Persist the preview past the session.

Props​

See the related component for its props.

Angular, Vue and HTML​

Register the elements once (Angular guide), then use <co-role-pill>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.

Angular template
<co-role-pill role="…" default-role="…" [roles]="roles" (co-open-change)="onOpenChange($event.detail)"></co-role-pill>
KindNameDescription
attributeroleRole currently previewed (controlled). Required unless `defaultRole` is set.
attributedefault-role / defaultRoleInitial role when uncontrolled; default ""
property / JSON attributerolesRoles offered in the menu. Required.
attributedefault-open / defaultOpenMenu open on first render; default false
attributeopenMenu open state (controlled); default uncontrolled
attributeclass-name / classNameClass on the wrapper
attributedefault-checked / defaultChecked
property / JSON attributedefault-value / defaultValue
attributeauto-focus / autoFocus
attributetype
attributedisabled
attributename
property / JSON attributevalue
eventco-open-changeCalled when the menu opens or closes; default none (React: onOpenChange)
eventco-changeCalled with the chosen role label; default none (React: onChange)