RolePill
ComplexAccess
<co-role-pill>RolePill shows which role the screen is previewed as ("Viewing as: Biller") and switches it.
import { RolePill } from 'health-components';
Examples
Open
Plain Roles
Usage
<RolePill role="Biller" roles={ROLES} onChange={setPreviewRole} />
When to use
- Admins previewing what another role sees; demos.
When not to use
- Changing a user's real role: Settings, Users.
Variants and states
| Variant | What it is |
|---|---|
| closed | Pill with eye icon and role. |
| open | Menu with a heading and the roles, current one marked. |
Accessibility
- Button named "Change the role you are viewing as", aria-haspopup menu.
Do and don't
- Do: Say in the menu that nothing is saved.
- Don't: Let a preview grant extra rights.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
role | string | — | Role currently previewed (controlled). Required unless `defaultRole` is set. |
defaultRole | string | "" | Initial role when uncontrolled |
roles * | RoleOption[] | — | Roles offered in the menu. Required. |
defaultOpen | boolean | false | Menu open on first render |
open | boolean | uncontrolled | Menu open state (controlled) |
onOpenChange | (open: boolean) => void | none | Called when the menu opens or closes |
onChange | (role: string) => void | none | Called with the chosen role label |
className | string | — | Class on the wrapper |
Also accepts native attributes, including defaultChecked, defaultValue, autoFocus, type, disabled, name, value, plus className and event handlers on the root element.
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) |