useSelectableCollection
Shared collection and value resolution utilities for compound selection primitives.
selectable-collection is the shared item registry used by compound selection components such as RadioGroup, CheckboxGroup, ToggleGroup, and CommandPalette.
Use it when building a custom compound primitive that needs DOM-order item registration, enabled-item filtering, or consistent fallback selection from highlighted, selected, and first enabled item.
Installation
dgadd ships in @diffgazer/add on npm: pnpm add -D @diffgazer/add puts it on pnpm exec, and npx @diffgazer/add runs it without the install.
UI components require Tailwind CSS v4. Local copy mode imports src/styles/styles.css; package mode uses @diffgazer/ui CSS from the installed package.
In copy mode the item writes three files — lib/selectable-collection.ts, lib/selectable-collection-observer.ts, and lib/selectable-group.ts — and pulls in the @diffgazer-keys/focusable registry item.
API
Usage
Notes
- The collection is sorted by DOM order, so keyboard traversal matches the rendered layout.
- Disabled items and items without mounted elements are excluded by
getEnabledSelectableCollectionItems. resolveSelectableCollectionItemtries candidates in order and falls back to the first enabled item.