Getting started

Actions

Forms

Layout

Navigation

Overlays

Feedback

Data display

Controllers

Helpers

Recipes

Tag Group

Tag groups display selected values as removable chips, commonly used in multi-select fields and filter bars.

Try it

reacttypescript

Usage

The live value property is always a string[] ([] when nothing is selected). The HTML attribute is those tokens as a comma-separated string. JSX may pass a string or an array; a string is parsed as CSV. input and change fire on the host and carry no detail; read host.value. Pass tags for the simple API, or compose RuiTagList and RuiTag. RuiTag already includes the remove control.

A named standalone tag group submits one native FormData entry per selected value and follows disabled fieldsets. Use required to require a selection. A plain form reset restores the initial selection, and browser state restoration recovers the saved selection.

import { RuiTagGroup, RuiTagList, RuiTag } from '@ecopages/radiant-ui/tag-group';

<RuiTagGroup value={['react', 'typescript']} selectionMode="multiple" label="Skills">
  <RuiTagList>
    <RuiTag value="react" label="React">React</RuiTag>
    <RuiTag value="typescript" label="TypeScript">TypeScript</RuiTag>
  </RuiTagList>
</RuiTagGroup>

Custom markup

<rui-tag-group> coordinates any light-DOM tree that matches its query contract. The Rui* helpers stamp these targets; they are not required.

import '@ecopages/radiant-ui/tag-group';

<rui-tag-group value="react" label="Skills">
  <div data-tag-list class="rui-tag-group__list">
    <span data-tag data-value="react" data-label="React" class="rui-tag">
      React
      <button type="button" data-tag-remove class="rui-tag__remove"></button>
    </span>
  </div>
</rui-tag-group>

BEM classes are presentation-only. Omit [data-tag-remove] for a non-removable tag. Add [data-ref="root"] around the list only if you call setItems().

Embedded in selects

Set embedded on the RuiTagGroup view when tags render inside a select or combobox trigger rather than standalone. The view stamps a plain [data-tag-group] wrapper without the <rui-tag-group> host, so no form-associated control sits inside the parent: the parent paints the chips, owns the value and removes a chip with its button, Backspace or Delete, announcing it with a bubbling rui-remove event.

Reordering

Set reorderable to let people reorder tags. Press and drag a tag, or focus it and press Space to lift it, arrow keys to move it, Space or Enter to drop it and Escape to cancel. Space lifts instead of selecting, so selection stays on click and Enter. Each step is announced through a visually hidden live region the host adds to itself. value is the selection and does not change with the order: listen for rui-reorder or read the tags in DOM order.

react

While a tag is lifted the host sets data-sortable-state="lifted" on it and data-sortable-drop="before" or "after" on the tag it would land beside, and --sortable-dx and --sortable-dy on the lifted tag follow the pointer. The theme draws them; the default styles show an insertion bar and lift the tag with the overlay shadow.

Theming

Tag Group surfaces map to semantic surface roles, never Tailwind palette steps:

PartCSS roles
Tag (rui-tag)surface, border, on-background, rounded-pill
Selected tag (rui-tag[aria-selected='true'])primary, on-primary
Remove control (rui-tag__remove)currentColor; hover on-background
Disabled tag--opacity-muted

Override roles at the theme layer, not in component CSS.

API

RuiTagGroup is a custom element (<rui-tag-group>) wrapping a focusable list of tags. Compose RuiTagList and RuiTag, pass tags to the helper, or stamp the light-DOM contract directly. It is form-associated.

Attributes

AttributeTypeDefaultDescription
valuestringomittedComma-separated selected tokens. Empty selection removes the attribute. The JS property is string[].
namestring''Submission name of a standalone tag group, with one FormData entry per selected value, and the key a surrounding RuiField registers the control under.
labelstring''Accessible name for the tag list.
requiredbooleanfalseRequire at least one selected value.
requiredMessagestring'Select at least one option.'Validation message of an empty required selection. Attribute: required-message.
disabledbooleanfalseDisable selection and removal.
selection-modesingle · multiplemultipleAllow one or many selected tags.
embeddedbooleanfalseView prop, not an attribute: renders a hostless [data-tag-group] for the chips of a select or combobox.
reorderablebooleanfalseLet tags be reordered by pointer drag or keyboard. See Reordering.

Light-DOM contract

TargetRequiredHost writesAuthor owns
[data-tag-list]yesid, role="list", aria-label, aria-disabledthe list node
[data-tag]yesid if missing, role="listitem", aria-selected, roving tabIndexdata-value, data-label, hidden, aria-disabled
[data-value]per tag—selection identity; fallback trimmed text
[data-label]per tag—remove accessible name; fallback trimmed text
[data-tag-remove]notype="button", tabIndex="-1", aria-label, disabled (group disabled or tag aria-disabled)presence
[data-ref="root"]for setItems()—wrapper around the list

Do not set role, aria-selected, or tabIndex on tags. Nested hosts: none.

Events

EventDetailDescription
inputnoneFired on each toggle, remove or clear, after value is updated.
changenoneFired right after input on the same interaction.
rui-remove{ value: string }Emitted when a tag is removed; value is the removed tag's value. Also followed by input and change.
rui-reorder{ value: string; from: number; to: number }Emitted after a reorder is applied: the moved tag's value and its old and new index among the tags that take part in keyboard movement (not hidden, not aria-disabled).

Methods

MethodDescription
resync()Re-read authored [data-tag] children after in-place DOM mutations.
setItems(items)Replace authored tags with a host-owned list. Requires [data-ref="root"].

View helpers

ComponentTarget stampedNotes
RuiTagGroup<rui-tag-group> + [data-ref="root"]Accepts tags (RuiTagData[]) or children.
RuiTagList[data-tag-list]Flex-wrap container.
RuiTag[data-tag], data-value, data-labelAlways includes RuiTagRemove.
RuiTagRemove[data-tag-remove]Host fills the accessible name on connect.

CSS classes

Public BEM classes on the composed light-DOM surface (documented via @cssclass):

ClassDescription
.rui-tag-groupRoot wrapper around the tag list.
.rui-tag-group__listTag row (flex-wrap container).
.rui-tagTag chip; selected state via [aria-selected='true'].
.rui-tag__removeTag remove control.

Theme roles

PartCSS variables consumed
Tag--surface, --border, --on-background, --radius-pill
Selected tag--primary, --on-primary
Remove hover--on-background
Disabled--opacity-muted
Reorder insertion bar--primary
Focus ring--focus-ring

Accessibility

  • Each tag exposes its label text to screen readers.
  • Remove buttons have accessible names indicating which tag will be removed (Remove {label}).
  • With selectionMode="multiple", Shift+click and Shift with an arrow key select the range of enabled tags from the last tag chosen or toggled, and Ctrl/Cmd+A selects every enabled tag.
  • A tag with aria-disabled="true" (disabled on RuiTag) is skipped by arrow keys and cannot be selected or removed: its remove control is disabled, and Delete and Backspace do nothing. After changing aria-disabled in place, call resync().
  • With reorderable, lifting, moving, dropping and cancelling are announced through a polite live region that the group appends to itself, cleared before each message so a repeated message, such as a second cancel, is announced again. While a tag is lifted the arrow keys move it instead of moving focus.
  • The group has an accessible name via label when not described by surrounding text.