Accordion
A vertical set of interactive headings that reveal sections of content.
Installation
Shadwire follows shadcn/ui's open code model: the component's source is copied into your application and becomes yours. Install it with the CLI:
The accordion registry item installs these files:
-
app/components/ui_component.rb -
app/components/ui/accordion_component.rb -
app/components/ui/accordion/item_component.rb -
app/components/ui/accordion/header_component.rb -
app/components/ui/accordion/trigger_component.rb -
app/components/ui/accordion/content_component.rb -
app/components/ui/accordion/panel_component.rb -
app/components/ui/icon_component.rb -
app/helpers/ui/accordion_helper.rb -
app/helpers/ui/icon_helper.rb -
app/javascript/controllers/ui_accordion_controller.js -
vendor/shadwire/shadwire.css
This component uses Stimulus, so the application needs importmap-rails and stimulus-rails with automatic controller loading.
Haven't installed the CLI yet? gem install shadwire, then shadwire init.
Usage
Use the Root > Item > Header > Trigger + Content composition.
The ui_accordion helper
takes the same arguments as Ui::AccordionComponent.
You can also render the ViewComponent classes directly:
Composition
The anatomy follows the Base UI reference shadcn uses: item, header,
trigger and content panel. ui_accordion_panel
is a name alias for ui_accordion_content.
Examples
Basic
A simple accordion showing one item at a time. The first item starts open.
Multiple
Use multiple: true to let several items stay open at once.
Disabled
Use disabled: true on an item to lock that panel.
Borders
Add border on the accordion to outline the group.
Card
Compose the Accordion inside a Card when it is part of a larger surface.
Subscription and billing
Common questions about plans, payments and cancellations.
API reference
The helpers wrap the ViewComponent classes and preserve free-form HTML attributes,
including data: and
aria:.
| Helper | Main arguments | Description |
|---|---|---|
ui_accordion |
multiple, default_value, orientation, disabled, loop_focus |
Root, with the Stimulus controller, initial values and keyboard navigation. |
ui_accordion_item |
value, disabled |
The item, with border-b last:border-b-0. Pass value whenever you set default_value. |
ui_accordion_header |
tag |
Renders the semantic heading; defaults to :h3. |
ui_accordion_trigger |
disabled |
The button that toggles the item, with a chevron-down icon and Stimulus actions. |
ui_accordion_content / ui_accordion_panel |
class / class_name |
The panel, with role="region", shadcn animations and an inner pt-0 pb-4 wrapper. |