Skip to main content

rc-chip

Chip wrapper for native button-based actions, filters, suggestions, and inputs.

Package
@rcarls/rc-chip
Element
<rc-chip>
Native dependency
Direct-child native button
State model
Selected/removable chip affordances
Main events
rc-chip-changerc-chip-remove

Installation

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

Markup

<rc-chip variant="filter">
<button type="button">Vegetarian</button>
</rc-chip>

<rc-chip variant="input" removable>
<button type="button" aria-label="Remove basil">Basil</button>
<span slot="remove-icon" class="material-symbols-outlined" aria-hidden="true"> close </span>
</rc-chip>

Filter chips toggle selected on user activation and add aria-pressed only when the author has not supplied stronger toggle semantics.

For removable chips, the direct native button is the sole removal action and fires rc-chip-remove. The trailing remove icon is presentational, so it does not add another tab stop or duplicate button semantics.

Without a theme, button and link chips retain their browser appearance. Packaged themes opt into chip sizing, shape, selection colors, and focus treatment.

Live demo

Groups

Compose interactive chips inside rc-toolbar when the group should form one tab stop with arrow-key navigation. Install and import @rcarls/rc-toolbar/define separately when you are not using the aggregate package:

<rc-toolbar label="Recipe filters">
<rc-chip variant="filter">
<button type="button">Quick</button>
</rc-chip>
<rc-chip variant="filter">
<button type="button">Vegetarian</button>
</rc-chip>
</rc-toolbar>

Toolbar layout does not wrap by default. A wrapping chip toolbar can opt in without changing its keyboard model:

rc-toolbar::part(root) {
flex-wrap: wrap;
}

API

Properties

PropertyMarkupTypeDefaultDescription
variantvariantRCChipVariant'assist'Chip variant.
selectedselectedbooleanNot specifiedCurrent selected state. Host writes are silent.
defaultSelecteddefault-selectedbooleanNot specifiedInitial selected state for uncontrolled usage.
disableddisabledbooleanfalseMirror disabled state to the native child button.
readonlyreadonlybooleanfalseMark this chip as non-interactive display content.
removableremovablebooleanfalseShow a trailing remove affordance.

Methods

No public methods are documented in the custom elements manifest.

Events

EventDetail typeDescription
rc-chip-removeCustomEventFired when a user activates a removable chip's native button.
rc-chip-changeNo detail type documentedFired when a user toggles a filter chip.

Slots

NameDescription
(default)A direct native `<button>` child, or `[data-rc-chip-label]` when `readonly`.
remove-iconOptional presentational remove icon.

CSS Custom Properties

PropertyDefaultDescription
--rc-chip-gap0pxGap between the slotted button/anchor/label's content.
--rc-chip-block-sizeNot specifiedMinimum chip block size (defers to native button/anchor sizing when unset).
--rc-chip-padding-blockNot specifiedBlock-axis padding of the slotted button, anchor, or label (defers to native padding when unset).
--rc-chip-padding-inlineNot specifiedInline-axis padding of the slotted button, anchor, or label (defers to native padding when unset).
--rc-chip-borderNot specifiedBorder of the slotted button, anchor, or label (defers to native border when unset).
--rc-chip-radiusNot specifiedBorder radius of the slotted button/anchor/label and the state-layer overlay (defers to native border-radius when unset; the state-layer overlay falls back to 0).
--rc-chip-bgNot specifiedBackground of the slotted button, anchor, or label (defers to native background when unset).
--rc-chip-colorNot specifiedText color of the slotted button, anchor, or label (defers to native color when unset).
--rc-chip-fontNot specifiedFont shorthand for the slotted button, anchor, or label (defers to native font when unset).
--rc-chip-text-decorationNot specifiedText decoration for the slotted anchor (defers to native text-decoration when unset).
--rc-chip-selected-border-colorNot specifiedBorder color when `selected` (defers to native styling when unset).
--rc-chip-selected-bgNot specifiedBackground when `selected` (defers to native styling when unset).
--rc-chip-selected-colorNot specifiedText color when `selected` (defers to native styling when unset).
--rc-chip-disabled-opacityNot specifiedOpacity of the slotted button when `disabled` (defers to native disabled styling when unset).
--rc-chip-focus-ringNot specifiedOutline shown while focus-within (defers to native focus styling when unset).
--rc-chip-focus-ring-offsetNot specifiedOutline offset while focus-within (defers to native focus styling when unset).
--rc-chip-state-layer-colorcurrentColorHover/focus/pressed state-layer color.
--rc-chip-selected-state-layer-colorvar(--rc-chip-state-layer-color, currentColor)Selected chip state-layer color.
--rc-chip-hover-state-layer-opacity0.08Hover state-layer opacity.
--rc-chip-focus-state-layer-opacity0.12Focus state-layer opacity.
--rc-chip-pressed-state-layer-opacity0.12Pressed state-layer opacity.
--rc-chip-state-layer-transition-durationvar(--rc-motion-effects-duration-fast,80ms)State-layer effects duration.
--rc-chip-state-layer-transition-easingvar(--rc-motion-effects-easing-fast,ease-out)State-layer effects easing.
--rc-chip-remove-offset-inline0.125remInline offset of the remove indicator from the chip edge.
--rc-chip-remove-target-size1.5remMinimum inline and block size of the remove indicator's hit target.
--rc-chip-remove-radius9999pxBorder radius of the remove indicator.
--rc-chip-remove-icon-sizesmallerFont size for a slotted remove icon.
--rc-chip-removable-padding-inline-endcalc(var(--rc-chip-remove-target-size, 1.5rem) - var(--rc-chip-gap, 0px))Override for removable chip content end padding.

CSS Parts

PartDescription
state-layerOverlay layer for hover, focus, pressed, ripple, or design-system effects.
removePresentational trailing remove indicator.