A compact, themeable chip component for displaying tags, filters, or selection tokens. Supports an optional remove button with a cancelable removal event and an exit animation. The consumer is responsible for removing the element from the DOM after handling the event.
<x-chip></x-chip>
| Attribute | Type | Default | Description |
|---|---|---|---|
label | string | — | Visible text content of the chip |
value | string | — | Value emitted in events; falls back to label when absent |
removable | boolean† | true | Whether the remove (×) button is rendered |
disabled | boolean | false | Disables all interaction; prevents remove events |
†removable uses default-true semantics: absent or empty string = true; removable="false" = false.
| Property | Type | Reflects attribute |
|---|---|---|
label | string | label |
value | string | value |
removable | boolean | removable |
disabled | boolean | disabled |
| Event | Bubbles | Composed | Cancelable | Detail |
|---|---|---|---|---|
x-chip-remove | yes | yes | yes | { value, label } |
x-chip-remove is dispatched before the exit animation begins. Call event.preventDefault() to cancel the removal — no animation plays and the chip stays in the DOM unchanged.
detail.value is the resolved value: the value attribute if set, otherwise the label attribute value.
| Part | Description |
|---|---|
container | Outer wrapper element |
label | Text label <span> |
remove | Remove button <button> (× symbol) |
| Variable | Default | Description |
|---|---|---|
--x-chip-bg | theme-dependent | Chip background color |
--x-chip-color | theme-dependent | Chip text color |
--x-chip-border | theme-dependent | Chip border color |
--x-chip-radius | 9999px | Border radius (pill by default) |
--x-chip-font-size | 0.8125rem | Label font size |
--x-chip-padding-x | 10px | Horizontal padding |
--x-chip-padding-y | 4px | Vertical padding |
--x-chip-remove-size | 16px | Remove button size |
--x-chip-exit-duration | 160ms | Exit animation duration |
Dark-mode defaults are set automatically via @media (prefers-color-scheme: dark).
role="listitem" on the host element when chips are used inside a role="list" container.tabindex="0" and aria-keyshortcuts="Backspace Delete" when removable is true and disabled is false.aria-disabled="true" and tabindex="-1" when disabled.[part=remove] has aria-label="Remove" and type="button".[part=label].| Key | Condition | Action |
|---|---|---|
Backspace or Delete | Host focused, removable, enabled | Attempts removal |
[part=remove] or presses Backspace/Delete on the host.x-chip-remove is dispatched (cancelable).preventDefault() is called → nothing happens.[data-exiting] attribute is set on the host, triggering the CSS exit animation.x-chip-remove and remove the element from the DOM (typically after the animation, or immediately).chip.addEventListener('x-chip-remove', e => {
// optionally wait for animation end, then:
e.target.remove();
});
<ul role="list" style="display:flex; gap:8px; list-style:none; padding:0">
<x-chip role="listitem" label="Design"></x-chip>
<x-chip role="listitem" label="Engineering"></x-chip>
<x-chip role="listitem" label="Marketing" value="mkt"></x-chip>
</ul>
<x-chip label="Read-only" removable="false"></x-chip>
<x-chip label="Archived" disabled></x-chip>
document.querySelectorAll('x-chip').forEach(chip => {
chip.addEventListener('x-chip-remove', e => {
e.target.remove();
});
});
chip.addEventListener('x-chip-remove', e => {
if (!canRemove(e.detail.value)) {
e.preventDefault();
}
});
[:x-chip {:label "Design" :role "listitem"}]
[:x-chip {:label "Read-only" :removable "false" :role "listitem"}]
[:x-chip {:label "Engineering"
:value "eng"
:role "listitem"
:on-x-chip-remove (fn [e] (.remove (.-target e)))}]
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |