Skip to content

feat(Chip): add CChipSet component and filter chips#457

Merged
mrholek merged 12 commits into
mainfrom
feat/chip-set
Jun 11, 2026
Merged

feat(Chip): add CChipSet component and filter chips#457
mrholek merged 12 commits into
mainfrom
feat/chip-set

Conversation

@mrholek

@mrholek mrholek commented Jun 10, 2026

Copy link
Copy Markdown
Member

Ports the recent vanilla coreui chip refactor (PR coreui/coreui#1098) to React: the new Chip set container and filter chips.

What's new

  • CChipSet (new component, own components/chip-set/ folder) — groups chips, lays them out (.chip-set), and coordinates selection (single/multiple via selectionMode, controlled value/defaultValue/onChange), removal, and roving focus. Forwards selectable, filter, removable, disabled, removeIcon, selectedIcon, and ariaRemoveLabel to its chips; each chip is identified by its value prop.
  • Filter chipsfilter prop on CChip (and CChipInput): implies selectable and shows a leading check icon while selected, customizable via selectedIcon.

Architecture

CChipSet and CChipInput are both built on a shared useChipSet hook — the React equivalent of vanilla's ChipInput extends ChipSet. The hook owns selection, roving focus, focus-a-neighbor-after-removal, and per-chip prop injection; CChipSet is a thin .chip-set wrapper and CChipInput adds only the text-input layer on top (no duplicated logic). Roving focus moved out of CChip into the hook — a standalone chip now only handles its own Enter/Space and Backspace/Delete, matching the vanilla split where the set owns navigation.

Chip existence stays with the caller: CChipSet removal fires onRemove (drop it from your data); CChipInput owns its value list and refocuses the input after removal.

Docs

New /components/chip-set/ page (overview, basic, selectable, single selection, filter, removable, keyboard, styling) mirroring the vanilla docs, plus a nav entry. Chip page keyboard section converted to tables and updated to reflect that arrow/Home/End navigation comes from the Chip set.

Tests

Unit tests for the filter chip and CChipSet (selection modes, controlled value, roving focus, removal). Full chip/chip-set/chip-input suites green.

mrholek added 12 commits June 10, 2026 16:14
Add CChipSet (own components/chip-set/ folder) for grouping chips, built on a
shared useChipSet hook — the React equivalent of the vanilla ChipInput extends
ChipSet. The hook owns selection coordination (single/multiple, controlled
value), roving focus, focus-a-neighbor-after-removal, and per-chip prop
injection; CChipSet is a thin .chip-set wrapper and CChipInput now builds on the
same hook instead of duplicating that logic, adding only the text-input layer.

Move roving focus out of CChip into the useChipSet engine; CChip handles only
its own Enter/Space and Backspace/Delete. The focusable-chip selector is shared
via chip/const.ts; chip identity in a set comes from the value prop
(chip-set/utils.ts).

Add a filter prop to CChip (implies selectable, leading check icon while
selected, customizable via selectedIcon) and to CChipInput.

Document CChipSet on a new /components/chip-set/ page (with styling) mirroring
the vanilla docs. Includes tests, docs examples, and API tables.
Roving focus stops at the last chip; in a chip input the text field sits after
the chips, so ArrowRight on the last chip now advances into it (mirroring
ArrowLeft at the start of the input focusing the last chip).
Roving focus between chips, ArrowRight-into-the-input from the last chip, and
ArrowLeft-to-the-last-chip from the input all swap left/right when rendered
right-to-left, via the existing isRTL util.
…ChipInput

CChipSet accepts a chips array (string | { value, label, ...CChipProps }) as an
alternative to composing CChip children, for programmatic creation; children are
used when chips is omitted. CChipInput now also seeds its initial chips from
declarative CChip children (parity with the vanilla Chip Input), with
defaultValue/value taking precedence. Per-chip overrides work in every mode.
…d; centralize data-driven chip building in useChipSet

CChipSet selection is now selected / defaultSelected (the set's value is the
selection, distinct from CChipInput where value is the chips). Move the
data-to-CChip-element mapping into useChipSet.renderChipsFromData so both
CChipSet (chips prop) and CChipInput (value list) share it instead of
duplicating it.
Matches the vanilla ChipSet 'select' event and CChipInput's onSelect; the set's
value is the selection, not the chip list.
Show the chips array as the primary form across the chip set examples (matching
the Chip Input docs) and note the CChip children alternative under the basic
example. Removes the now-redundant standalone 'Rendering from data' example.
…terfaces

chips before className and selected between selectable/selectedIcon in CChipSet;
chipClassName before className in CChipInput. Matches the propTypes order.
Mirrors the controlled/uncontrolled pattern already used for selection. With
defaultChips the set owns the list and removes chips itself (onRemove only
notifies); chips/children stay controlled. Removable docs example simplified to
defaultChips (no useState).
A disabled chip is not interactive, so it no longer renders a remove button (parity with the vanilla Chip).
- selectionMode ('single' | 'multiple') is forwarded to the shared chip-set engine
- the hidden form input is always rendered, with name falling back to a generated id (parity with the vanilla Chip Input)
@mrholek mrholek merged commit 28a3ff1 into main Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant