Skip to main content

rc-chip-group

Adaptive wrapping and horizontal-scrolling layout for chip collections and arbitrary direct children.

Package
@rcarls/rc-chip-group
Element
<rc-chip-group>
Native dependency
Author-owned fieldset and radio/checkbox controls
State model
Auto overflow disclosure and optional assist roving focus
Main events
rc-chip-group-toggle

Installation​

npm install @rcarls/rc-webcomponents@next
import '@rcarls/rc-webcomponents/rc-chip-group/define';

The define entry also registers rc-chip, which the group uses for its internal Show all/Show less action.

Usage​

Keep fieldset, legend, form value, and selection semantics native:

<fieldset>
<legend>Recipe scope</legend>
<rc-chip-group kind="filter" selection="single">
<rc-chip>
<label><input type="radio" name="scope" value="all" checked />All</label>
</rc-chip>
<rc-chip>
<label><input type="radio" name="scope" value="favorites" />Favorites</label>
</rc-chip>
</rc-chip-group>
</fieldset>

Use selection="multiple" with checkboxes. Use selection="none" for menu-backed filter buttons with aria-haspopup; their menu owns the eventual selection.

Live demo​

Accessibility​

  • kind="filter" keeps the native radios or checkboxes as the selection controls, so the author's fieldset and legend name the group and each input keeps its role, label, and checked state.
  • kind="assist" gives the group role="toolbar" and an aria-label from label. It is a single tab stop: arrow keys along the row move between chips, wrapping, and Home and End move to the first and last chip. The arrow keys follow the inline direction, so Left and Right swap in right-to-left text.
  • kind="generic" adds no role or keyboard behavior.

The Show all and Show less action is a native button whose name changes with the state, and its icon and separator are decorative.

Adaptive layout​

layout="auto" is the default. The group first measures its natural wrapped layout. When the content needs more than max-rows="2", it becomes one horizontally scrolling row and inserts a leading Show all action. Expanded content returns to natural wrapping and the same action becomes Show less. The action uses the MDI tune icon and a vertical separator to distinguish the disclosure control from the authored chip collection.

Use layout="wrap" to always wrap or layout="scroll" to always keep one horizontal row. The component uses actual rendered rows, so container size, text scaling, localization, and consumer content all participate in the decision without device-pixel-ratio special cases.

Coordination modes​

  • kind="generic" is layout-only and accepts any direct HTMLElement.
  • kind="assist" exposes a labeled toolbar with one tab stop and horizontal arrow/Home/End navigation.
  • kind="filter" synchronizes native radio/checkbox state to direct rc-chip children. Put the group inside an author-owned fieldset.

Localization​

Built-in text follows the element's own lang, else <html lang>. Override it with messages, or register it for every instance under rc-chip-group: label, showAll, showLess. See Localization.

API​

Properties​

PropertyMarkupTypeDefaultDescription
messagesJS property onlyPartial<RCChipGroupMessages> | undefinedNot specifiedBuilt-in text overrides; unset keys fall back to registered text, then English.
layoutlayoutRCChipGroupLayout'auto'Layout strategy.
maxRowsmax-rowsnumber2Maximum natural rows before auto layout collapses to horizontal scrolling.
kindkindRCChipGroupKind'generic'Child coordination mode.
selectionselectionRCChipGroupSelection'none'Native filter selection hint.
labellabelstring | undefinedNot specifiedAccessible label used when `kind="assist"` exposes toolbar semantics. Defaults to the `label` message.
expandedexpandedbooleanNot specifiedCurrent auto-layout disclosure state. Host writes are silent.
defaultExpandeddefault-expandedbooleanNot specifiedInitial uncontrolled disclosure state.

Events​

EventDetail typeDescription
rc-chip-group-toggleNo detail type documentedFired after the user activates Show all or Show less.

Slots​

NameDescription
(default)Direct chip or arbitrary-element children.

CSS Custom Properties​

PropertyDefaultDescription
--rc-chip-group-column-gap0.5remInline gap between items.
--rc-chip-group-row-gap0Block gap between wrapped rows. Slotted readonly chips keep `--rc-chip-touch-target-block-size` so every row shares the disclosure toggle's pitch.
--rc-chip-touch-target-block-size3remShared row pitch for readonly chips and the disclosure toggle.
--rc-chip-group-padding-block0Group block-axis padding.
--rc-chip-group-scroll-padding-inline0Horizontal scroll padding.
--rc-chip-group-scrollbar-widthnoneStandards-based scrollbar width.
--rc-chip-group-scrollbar-displaynoneWebKit scrollbar display.
--rc-chip-group-toggle-gap0.5remGap between the disclosure icon and label.
--rc-chip-group-toggle-separator-gap0.5remGap before the disclosure separator.
--rc-chip-group-toggle-icon-size1.125remDisclosure icon size.
--rc-chip-group-toggle-separator-block-size1.5remSeparator block size.
--rc-chip-group-toggle-separator-inline-size1pxSeparator thickness.
--rc-chip-group-toggle-separator-colorcurrentColorSeparator color.

CSS Parts​

PartDescription
rootFlex layout and horizontal scroll container.
toggleInternal leading disclosure chip.
toggle-iconMDI tune icon inside the disclosure chip.
toggle-separatorVertical separator after the disclosure chip.