--- package: "@svenskaspel/ui" version: "4.4.0" document_type: "component-documentation" source: "@svenskaspel/ui/docs/accordion.md" canonical_url: "/components/accordion" usage_source: "src/app/(docs)/components/accordion/page.mdx" --- # Accordion Accordion is a container with a header that can be expanded to reveal additional content. Multiple accordion elements may be grouped together.  *** ## Usage Use Accordion in scenarios where you need to provide additional information or controls. Example uses can be among others: Q\&A articles in a help section or additional form controls that are not mandatory for completion of a task. ### Content Consider what content is appropriate to place within an accordion.  > **Do:** Use Accordion to reveal optional or extra information or controls.  > **Don't:** Don’t hide critical information or mandatory controls in a form inside an accordion. ### Alternatives Specifically for contextual help, a contextual dialog may be the preferrable choice of component. *** ## Formatting ### Anatomy Accordion consists of a frame containing a title and an icon, along with a content section in its expanded state.  1. Title 2. Stroke 3. Icon 4. Content ### Title The title of the frame displayed both in the collapsed and expanded state. The title text may overflow into multiple lines if required. ### Stroke The stroke serves as a visual divider between the base items of the Accordion, helping to distinguish individual sections and improve readability." ### Icon The icon indicating whether the accordion is currently in its collapsed or expanded state. When transitioning between the collapsed and expanded states the icon rotates 180 degrees in a brief animation. ### Content The content revealed in the expanded state. *** ## Behaviour ### States When interacted with, the frame expands from the collapsed state, revealing additional content. Unlike for example a dropdown menu, accordion pushes other content (or other accordion elements in the group) located below.  Collapsed  Expanded *** ## Modify Accordion can be extended or contracted horizontally as desired but usually expands to the horizontal edges of the surrounding frame. ### Title A helpful title indicating what the user could expect to be revealed when interacting with the component. ### Content Accordion allows for certain freedom in what content it may contain. Typically, the content of the expandable section is text, or a list, such as an article or a help section. More complex content such as graphics or additional form controls can also be considered appropriate. ### Theme A flat version of accordion is available, stripped of borders and elevation, intended to be used within a card with a expandable sub section. --- # Readme / API # `Accordion` The `Accordion` component is a reusable accordion built on top of the [Base UI Accordion](https://base-ui.com/react/components/accordion) primitive. ## Importing ```typescript import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from '@svenskaspel/ui/react/accordion'; ``` ## Sub-components The `Accordion` component consists of several sub-components: - `AccordionItem`: Represents an item in the accordion. - `AccordionTrigger`: Represents the trigger for the accordion item. - `AccordionContent`: Represents the content (panel) of the accordion item. ## Props Each sub-component accepts all the props that their corresponding primitive component from `@base-ui/react/accordion` accepts. They also accept a `className` prop for additional styling. ### For the main `Accordion` component: - **`multiple`**: `boolean` (Optional, defaults to `false`) - Description: Whether multiple items can be open at the same time. When omitted, the accordion behaves like a single-open accordion where the currently open item can always be closed by clicking its trigger again. - **`value`**: `unknown[]` (Optional) - Description: The controlled value of the currently open item(s). This is always an array — even when only a single item is open at a time, wrap the value in an array (e.g. `['item-1']`). - **`defaultValue`**: `unknown[]` (Optional) - Description: The value of the item(s) to be open by default when the accordion is first rendered (for uncontrolled state). Always an array. - **`onValueChange`**: `(value: unknown[], eventDetails) => void` (Optional) - Description: A callback function that is called when the open item(s) change. The first argument is always an array of the currently open values. - **`disabled`**: `boolean` (Optional) - Description: If `true`, all items within the accordion will be disabled and cannot be interacted with. Defaults to `false`. ### For the `AccordionContent` sub-component: - **`hiddenUntilFound`**: `boolean` (Optional) - Description: Allows the browser's built-in page search to find and expand the panel contents. Overrides `keepMounted` and uses `hidden="until-found"` to hide the element without removing it from the DOM. Defaults to `false`. - **`keepMounted`**: `boolean` (Optional) - Description: Whether to keep panels in the DOM while closed. Ignored when `hiddenUntilFound` is used. Defaults to `false`. These panel props belong on `AccordionContent`, not on the `Accordion` root. ### For the `AccordionItem` sub-component: - **`value`**: `unknown` (Optional — an internal value is generated when omitted) - Description: A unique identifier for this accordion item. This value is what appears in the parent `Accordion`'s `value`/`defaultValue`/`onValueChange` array to indicate whether the item is open. - **`disabled`**: `boolean` (Optional) - Description: If `true`, this specific accordion item will be disabled and cannot be opened or closed. Defaults to `false`. ### For the `AccordionTrigger` sub-component: - **`headerTag`**: `keyof React.JSX.IntrinsicElements` (Optional, defaults to `'h3'`) - Description: Controls the HTML element used for the accordion header wrapper. Accepts any valid HTML tag name (e.g., `'h1'`–`'h6'`, `'div'`, `'p'`, `'span'`). By default, a `
Yes. It adheres to the WAI-ARIA design pattern - woohoo.
Yes. It adheres to the WAI-ARIA design pattern - woohoo.
Yes. It adheres to the WAI-ARIA design pattern - woohoo.