Перейти до вмісту

Segmented control

Цю сторінку ще не перекладено, тому вона показана мовою оригіналу.

One choice out of a few, as segments on a recessed track. It is a group of native radios, so it submits and resets with its form and works without JS. Arrow keys move the choice (mirrored in RTL sections), and Tab enters the group once.

Example

<div>
  <div class="ms-segmented-control" role="radiogroup" aria-label="Accent">
    <label class="ms-segmented-control__item">
      <input
        type="radio"
        class="ms-segmented-control__input"
        name="preview-accent"
        value="violet"
        checked
      />
      <span class="ms-segmented-control__label">Violet</span>
    </label>
    <label class="ms-segmented-control__item">
      <input
        type="radio"
        class="ms-segmented-control__input"
        name="preview-accent"
        value="orange"
      />
      <span class="ms-segmented-control__label">Orange</span>
    </label>
    <label class="ms-segmented-control__item">
      <input
        type="radio"
        class="ms-segmented-control__input"
        name="preview-accent"
        value="ink"
      />
      <span class="ms-segmented-control__label">Ink</span>
    </label>
  </div>
</div>

Sizes

As tall as a control of the same size, so it lines up with buttons and inputs in a toolbar.

<div style="display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem">
  <div
    class="ms-segmented-control ms-segmented-control--size-sm"
    role="radiogroup"
    aria-label="Density, small"
  >
    <label class="ms-segmented-control__item">
      <input
        type="radio"
        class="ms-segmented-control__input"
        name="preview-density-sm"
        checked
      />
      <span class="ms-segmented-control__label">Comfortable</span>
    </label>
    <label class="ms-segmented-control__item">
      <input
        type="radio"
        class="ms-segmented-control__input"
        name="preview-density-sm"
      />
      <span class="ms-segmented-control__label">Compact</span>
    </label>
  </div>
  <button
    class="ms-background ms-border ms-surface ms-surface--hover-all ms-surface--variant-outlined ms-control ms-control--size-sm ms-button"
    type="button"
  >
    Small button
  </button>
</div>
<div
  style="display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin-block-start: 1rem"
>
  <div class="ms-segmented-control" role="radiogroup" aria-label="Density">
    <label class="ms-segmented-control__item">
      <input
        type="radio"
        class="ms-segmented-control__input"
        name="preview-density"
        checked
      />
      <span class="ms-segmented-control__label">Comfortable</span>
    </label>
    <label class="ms-segmented-control__item">
      <input
        type="radio"
        class="ms-segmented-control__input"
        name="preview-density"
      />
      <span class="ms-segmented-control__label">Compact</span>
    </label>
  </div>
  <button
    class="ms-background ms-border ms-surface ms-surface--hover-all ms-surface--variant-solid ms-control ms-button"
    type="button"
  >
    Base button
  </button>
</div>

Usage

<div
  class="ms-segmented-control ms-segmented-control--size-base"
  role="radiogroup"
  aria-label="Accent"
>
  <label class="ms-segmented-control__item">
    <input
      type="radio"
      class="ms-segmented-control__input"
      name="accent"
      value="violet"
      checked
    />
    <span class="ms-segmented-control__label">Violet</span>
  </label>
  <label class="ms-segmented-control__item">
    <input
      type="radio"
      class="ms-segmented-control__input"
      name="accent"
      value="orange"
    />
    <span class="ms-segmented-control__label">Orange</span>
  </label>
</div>
Prop / class Values
sgcSize · --size-{size} sm (32px) · base (40px, default) · lg (48px)
sgcIsFullWidth · --full-width the track fills its container, the segments share it equally
  • The radio is hidden but stays focusable and announced; its label shows the focus ring.
  • The track's padding and border come off the segments, so the whole control keeps the control height. Segment corners are concentric with the track (--ms-segmented-control-item-radius).
  • The selected segment is raised on --ms-color-bg-raised, the track sits on --ms-color-bg-sunken; see the tokens.
  • React: SegmentedControl from @mainset/react/components, controlled (sgcValue, sgcOnChange).