Skip to main content

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​

Storybook

Plain Roles​

Storybook

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​

VariantWhat it is
closedPill with eye icon and role.
openMenu 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​

PropTypeDefaultDescription
rolestring—Role currently previewed (controlled). Required unless `defaultRole` is set.
defaultRolestring""Initial role when uncontrolled
roles *RoleOption[]—Roles offered in the menu. Required.
defaultOpenbooleanfalseMenu open on first render
openbooleanuncontrolledMenu open state (controlled)
onOpenChange(open: boolean) => voidnoneCalled when the menu opens or closes
onChange(role: string) => voidnoneCalled with the chosen role label
classNamestring—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>
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)