feat(Chip): add CChipSet component and filter chips#457
Merged
Conversation
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports the recent vanilla
coreuichip refactor (PR coreui/coreui#1098) to React: the new Chip set container and filter chips.What's new
CChipSet(new component, owncomponents/chip-set/folder) — groups chips, lays them out (.chip-set), and coordinates selection (single/multipleviaselectionMode, controlledvalue/defaultValue/onChange), removal, and roving focus. Forwardsselectable,filter,removable,disabled,removeIcon,selectedIcon, andariaRemoveLabelto its chips; each chip is identified by itsvalueprop.filterprop onCChip(andCChipInput): impliesselectableand shows a leading check icon while selected, customizable viaselectedIcon.Architecture
CChipSetandCChipInputare both built on a shareduseChipSethook — the React equivalent of vanilla'sChipInput extends ChipSet. The hook owns selection, roving focus, focus-a-neighbor-after-removal, and per-chip prop injection;CChipSetis a thin.chip-setwrapper andCChipInputadds only the text-input layer on top (no duplicated logic). Roving focus moved out ofCChipinto the hook — a standalone chip now only handles its ownEnter/SpaceandBackspace/Delete, matching the vanilla split where the set owns navigation.Chip existence stays with the caller:
CChipSetremoval firesonRemove(drop it from your data);CChipInputowns 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
filterchip andCChipSet(selection modes, controlled value, roving focus, removal). Full chip/chip-set/chip-input suites green.