Native Web Components playground

Nova v3.37.0

Preview

Web Components

Toggle button

nv-togglebutton

Buttons that stay on or off, alone or in a group, for selecting options or switching views.

Parts

Live demo

Emphasis
Size

Use toggle buttons to switch a setting on or off, or to choose one or more options from a small set. In a toggle button group they look like a button group but keep a selected state. For actions without a lasting state, use a button group.

Anatomy

A toggle button group with Action 1, a selected Action 2 and an icon-only button. Callout 1 marks the text toggle button, callout 2 the icon-only toggle button.

A toggle button group with text and icon-only toggles.
  1. Toggle button with a text label; a selected toggle is highlighted.
  2. Icon-only toggle button for compact controls; give it an aria-label.

Put a label and any leading or trailing nv-icon elements in the default slot. The design supports icons on either side, but nv-togglebutton has no separate named icon slots.

Selection

A toggle button group holds the selected values. exclusive allows one choice, and enforceValue keeps at least one selected. A toggle button on its own does not change state by itself: set active from the toggled event.

Emphasis, size and states

Emphasis is high (default) or low, sizes run from xs to lg, and a group applies both to all its buttons. States are default, hover, focus, selected and disabled.

These states follow the current Spark or Ocean theme. There are two emphasis values, high and low; the design page's reference to “four” is a wording error. Keep the same emphasis and size throughout one group.

high · default
low
xs
sm
md · default
lg

Accessibility

An enabled toggle is keyboard focusable and responds to Enter and Space. active is announced through aria-pressed; disabling the toggle removes it from the tab sequence. Use a visible focus indicator and name icon-only toggles with aria-label so their selected state has a clear meaning.

Guidelines

  • Use clear labels or icons that reflect the toggled state.
  • Choose single or multiple selection deliberately.
  • Keep one emphasis level within a group.
DoUse labels or icons that name what turns on.
Don'tAvoid toggles for one-off actions; use a button group.

Sources