feat(react): add the Accordion primitive#18
Open
ivanbanov wants to merge 2 commits into
Open
Conversation
Adds @dunky.dev/accordion (framework-free state machine) and @dunky.dev/react-accordion (React binding). Anatomy: Accordion root (renders no element) > Item > Header > Trigger, plus Content. Stacked disclosure sections per the WAI-ARIA APG pattern: single (optionally collapsible) or multiple open items, orientation-aware arrow/Home/End trigger navigation, and an authoritative controlled value. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
Adds the Accordion primitive as two packages:
@dunky.dev/accordion— the framework-free core: a state machine (built on@dunky.dev/state-machine) owning the open set, toggle gating, and keyboard-focus movement.@dunky.dev/react-accordion— the thin React binding that renders the compound parts and carries the machine's decisions to the DOM.An accordion is a stacked set of headers, each expanding or collapsing a section beneath it, per the WAI-ARIA APG pattern. The
typediscriminant picks the value shape (singlespeaksstring | null,multiplespeaksstring[]), so two open items in single mode is unrepresentable. A controlledvalueis authoritative: a press reports the value it asked for throughonValueChangeand the UI follows the prop.Anatomy
Behavior
collapsibleopts into closing the open item. Multiple mode toggles freely.orientation(vertical: ArrowDown/ArrowUp; horizontal: ArrowRight/ArrowLeft). Home / End jump to the first / last enabled trigger. Disabled items are skipped; a disabled accordion leaves the keys to the page.aria-expanded+aria-controls; content is arole="region"labelled by its trigger; ids derive from the root id plus the URI-encoded item value so cross-references always resolve. Disabled triggers — and the open trigger in single non-collapsible mode, per APG — exposearia-disabledwhile staying focusable.data-state(open/closed),data-disabled, anddata-orientation.Test plan
pnpm test:ci— 133 tests, 9 files, all passingpnpm typecheckpnpm lintpnpm format:checkpnpm build🤖 Generated with Claude Code