Skip to content

HyChip

Usage examples on this page are written for Lit / plain HTML (<hy-chip>). The same component ships as HyChip in @whitespaceux/harmony-react (native React 19), with typed wrappers for Angular, Solid, Svelte, and Vue. The API reference below applies to all frameworks.

A compact, interactive element for displaying tags, filters, selections, or actions.

Chips are versatile UI elements that can represent inputs, attributes, or actions. Unlike badges (which are non-interactive status indicators), chips support user interaction including clicking, selecting, and removing.

Key Features

  • Multiple semantic variants (neutral, brand, success, warning, danger, info)
  • Optional remove button for dismissible chips
  • Selectable state for filter/toggle scenarios
  • Link mode when href is provided
  • Icon and avatar support via prefix/suffix slots
  • Full keyboard navigation (Enter, Space, Backspace, Delete)
  • SSR compatible

Accessibility Features

  • Proper ARIA roles and states
  • Keyboard navigation with focus indicators
  • Screen reader announcements
  • High contrast mode support
  • Reduced motion support

Examples

Basic Chip

html
<hy-chip>Label</hy-chip>

With Icon

html
<hy-chip icon="favorite-border">Favorites</hy-chip>

Removable Chip

html
<hy-chip removable>Removable</hy-chip>

Selectable Chip

html
<hy-chip selected>Selected</hy-chip>
html
<hy-chip href="/category/design">Design</hy-chip>

Variants

html
<hy-chip variant="neutral">Neutral</hy-chip>
<hy-chip variant="brand">Brand</hy-chip>
<hy-chip variant="success">Success</hy-chip>
<hy-chip variant="warning">Warning</hy-chip>
<hy-chip variant="danger">Danger</hy-chip>

Categorical / Identity tag

html
<!-- Hash an identity string to a stable slot in a named group. -->
<hy-chip category-group="team" identity="user-alice">Alice</hy-chip>
<!-- Explicit slot beats identity. -->
<hy-chip category-group="team" slot-index="3">Frontend</hy-chip>
<!-- A non-neutral variant wins — categorical is ignored. -->
<hy-chip variant="brand" category-group="team" slot-index="3">Brand (categorical skipped)</hy-chip>

Event Handling

css
const chip = document.querySelector('hy-chip[removable]');

chip.addEventListener('remove', (event) => {
console.log('Chip removed:', event.detail.chip);
event.detail.chip.remove(); // Remove from DOM
});

chip.addEventListener('select', (event) => {
console.log('Selection changed:', event.detail.selected);
});

API

Properties

PropertyAttributeTypeDefaultDescription
variantvariant'neutral' | 'brand' | 'success' | 'warning' | 'danger' | 'info''neutral'Visual style variant determining the chip's color scheme and semantic meaning.
emphasisemphasis'solid' | 'soft' | 'outlined' | 'tinted''soft'Visual chrome weight on top of the role.
sizesize'small' | 'medium' | 'large''medium'Physical size of the chip affecting dimensions, padding, and typography.
interactiveinteractivebooleantrueWhether the chip is interactive (clickable, focusable, and responds to keyboard). When false, the chip renders as a static display element without button semantics, making it suitable for tags or labels that don't require user interaction.
removableremovablebooleanfalseShows a remove button that allows the user to dismiss the chip. When clicked, fires the remove event. The chip can also be removed by pressing Backspace or Delete when focused.
disableddisabledbooleanfalseDisables the chip, preventing interaction and applying disabled styling. Disabled chips cannot be clicked, selected, or removed.
selectedselectedbooleanfalseIndicates whether the chip is in a selected state. Useful for filter chips, toggle chips, or multi-select scenarios. Clicking a selectable chip toggles this state and fires select.
hrefhrefstring | undefinedWhen set, renders the chip as an <a> tag with this href. The chip will navigate to the specified URL when clicked.
targettarget'_blank' | '_parent' | '_self' | '_top'Specifies where to open the linked document. Only used when href is set. When set to _blank, automatically adds rel="noreferrer noopener" for security.
removeLabelremove-labelstring | undefinedCustom label for the remove button used by assistive technologies. If not provided, defaults to "Remove {chip text content}" for better context.
iconiconstring | undefinedName of the icon to display before the label. When set, renders an hy-icon in the shadow DOM instead of using the prefix slot.
categoryGroupcategory-groupstring | undefinedCategorical group name to hash into. Only applied when variant is neutral; a non-neutral variant wins. Selects which palette in the active DS's roles.categorical map this chip pulls from.
identityidentitystring | undefinedIdentity string hashed to a stable slot within categoryGroup — same identity always produces the same color. Ignored when slotIndex is set.
slotIndexslot-indexnumber | undefinedExplicit 1-indexed slot within categoryGroup. Takes precedence over identity. Out-of-range values fall back to default styling.

Events

EventDetailDescription
activateFired when chip is clicked. Detail: { originalEvent: MouseEvent | KeyboardEvent }
removeFired when remove button is clicked or Backspace/Delete pressed. Detail: { chip: HyChip, originalEvent: MouseEvent | KeyboardEvent }
selectFired when chip selection state changes. Detail: { selected: boolean, originalEvent: MouseEvent | KeyboardEvent }

Slots

SlotDescription
defaultThe chip's label text
prefixContent before the label (icon, avatar)
suffixContent after the label, before remove button (icon, count)
remove-iconCustom remove icon (overrides the default close icon; only rendered when removable)

CSS Parts

PartDescription
baseThe chip's base wrapper element
labelThe default slot containing chip text
remove-buttonThe remove button element (when removable)

CSS Custom Properties

PropertyDescription
--hy-chip-gapGap between elements
--hy-chip-height-smHeight at small size
--hy-chip-height-mdHeight at medium size
--hy-chip-height-lgHeight at large size
--hy-chip-padding-inline-smHorizontal padding at small size
--hy-chip-padding-inline-mdHorizontal padding at medium size
--hy-chip-padding-inline-lgHorizontal padding at large size
--hy-chip-radiusBorder radius
--hy-chip-strokeBorder width
--hy-chip-opacity-disabledOpacity when disabled
--hy-chip-remove-opacityOpacity of the remove button
--hy-chip-text-transformText transform for chip label
--hy-chip-font-familyFont family override for chip label
--hy-chip-foreground-on-inverse-surfaceText color for neutral selected chips Default: var(--hy-background-surface-base)
--hy-chip-hover-durationTransition duration for hover and focus state feedback
--hy-chip-hover-easingTransition easing for hover and focus state feedback

Methods

focus()

Sets focus on the chip.

blur()

Removes focus from the chip.

Built with Lit. Documented with VitePress.