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
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
| Variant | What it is |
|---|---|
| closed / open | See RolePill. |
| on navy | Inside 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>
| Kind | Name | Description |
|---|---|---|
| attribute | role | Role currently previewed (controlled). Required unless `defaultRole` is set. |
| attribute | default-role / defaultRole | Initial role when uncontrolled; default "" |
| property / JSON attribute | roles | Roles offered in the menu. Required. |
| attribute | default-open / defaultOpen | Menu open on first render; default false |
| attribute | open | Menu open state (controlled); default uncontrolled |
| attribute | class-name / className | Class on the wrapper |
| attribute | default-checked / defaultChecked | |
| property / JSON attribute | default-value / defaultValue | |
| attribute | auto-focus / autoFocus | |
| attribute | type | |
| attribute | disabled | |
| attribute | name | |
| property / JSON attribute | value | |
| event | co-open-change | Called when the menu opens or closes; default none (React: onOpenChange) |
| event | co-change | Called with the chosen role label; default none (React: onChange) |