Tag Group
Tag groups display selected values as removable chips, commonly used in multi-select fields and filter bars.
Try it
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.
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:
| Part | CSS 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
| Attribute | Type | Default | Description |
|---|---|---|---|
value | string | omitted | Comma-separated selected tokens. Empty selection removes the attribute. The JS property is string[]. |
name | string | '' | Submission name of a standalone tag group, with one FormData entry per selected value, and the key a surrounding RuiField registers the control under. |
label | string | '' | Accessible name for the tag list. |
required | boolean | false | Require at least one selected value. |
requiredMessage | string | 'Select at least one option.' | Validation message of an empty required selection. Attribute: required-message. |
disabled | boolean | false | Disable selection and removal. |
selection-mode | single · multiple | multiple | Allow one or many selected tags. |
embedded | boolean | false | View prop, not an attribute: renders a hostless [data-tag-group] for the chips of a select or combobox. |
reorderable | boolean | false | Let tags be reordered by pointer drag or keyboard. See Reordering. |
Light-DOM contract
| Target | Required | Host writes | Author owns |
|---|---|---|---|
[data-tag-list] | yes | id, role="list", aria-label, aria-disabled | the list node |
[data-tag] | yes | id if missing, role="listitem", aria-selected, roving tabIndex | data-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] | no | type="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
| Event | Detail | Description |
|---|---|---|
input | none | Fired on each toggle, remove or clear, after value is updated. |
change | none | Fired 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
| Method | Description |
|---|---|
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
| Component | Target stamped | Notes |
|---|---|---|
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-label | Always 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):
| Class | Description |
|---|---|
.rui-tag-group | Root wrapper around the tag list. |
.rui-tag-group__list | Tag row (flex-wrap container). |
.rui-tag | Tag chip; selected state via [aria-selected='true']. |
.rui-tag__remove | Tag remove control. |
Theme roles
| Part | CSS 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"(disabledonRuiTag) is skipped by arrow keys and cannot be selected or removed: its remove control is disabled, and Delete and Backspace do nothing. After changingaria-disabledin place, callresync(). - 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
labelwhen not described by surrounding text.