Skip to content

DocsFormsSegmented

PT

Forms

Segmented

Toggle with a few options and an indicator that slides to the chosen one.

data-u="segmented"

Example

Installation

Segmented ships in the full package, in unslop.css and unslop.js:

curl -fsSL unslop.leallabs.dev/i | sh

A ready-made block that uses segmented:

curl -fsSL unslop.leallabs.dev/i | sh -s add wall-controls

No build Name-based add is for charts and blocks. Components with JS live in unslop.js, which mounts every data-u on the page by itself.

Props

No props. The options are the child buttons and the initial one is the one with aria-checked="true".

Classes and variants

ClassWhat it does
u-seg--flatOn the host: flat version, without the sunken background.

Accessibility and keyboard

State and roles

WhereAttributeWhat it says
hostrole="radiogroup"Set by the JS. Give the host an aria-label.
buttonsrole="radio", aria-checkedThe chosen one has aria-checked="true" and is the only one with tabindex 0.

Keyboard

KeyDoes
Tabenters the group, straight on the chosen option
Arrowschange the option and wrap around at the end

Events and API

EventdetailWhen
u:change{ index, label }Only when the change comes from the user, not on mount.

Every event bubbles up the page. Listen on the element itself: el.addEventListener("u:change", (e) => e.detail).

Type to search. Arrows pick, Enter opens.