Accordion

Accordions display a list of high-level options that can expand/collapse to reveal more information.

Panel Header
Panel Header2
Panel Header3

Installation

If @melio-ui/react is already installed globally, you can skip this step.

Import

  • AccordionRoot: All parts of the accordion are included.
  • AccordionItem: Includes all parts of the collapsible section.
  • AccordionHeader: This item switches the expand/collapse state of the accordion item. This item has a titled element.
  • AccordionArrow: Down arrow icon rotating based on expand/collapse state.
  • AccordionContent: Contains the collapsible content for an item.

Another way to import

'use client';
import { Accordion } from '@melio-ui/accordion';
<Accordion.Root>
<Accordion.Item>
<Accordion.Header>
<div>Panel Title1</div>
<Accordion.ArrowIcon />
</Accordion.Header>
<Accordion.Content>Content1</Accordion.Content>
</Accordion.Item>
</Accordion.Root>;

'use client' must be used when rendering on the server side.

API Reference

AccordionRoot

All parts of the accordion are included.

PropTypeDefaultDescription
valueExpandedValueType-The value of the expanded accordion item.
defaultValueExpandedValueType-The initial value of the expanded accordion item.
togglebooleanfalseaccordion item can be collapsed again it or not.
multiplebooleanfalsemultiple accordion item can be expanded at once or not.
disabledbooleanfalseall the accordion item will be disabled or not.
renderMode"selecting" | "selected" | "force""selecting"How to render accordion item.

selecting: Rendering only the currently expanded accordion item.
selected: Rendering accordion items that have been expanded.
force: Rendering all accordion items.
onValueChange(value: ExpandedValueType) => void-The callback invoked when expanded or collapsed an accordion item.

AccordionItem

Includes all parts of the collapsible section.

PropTypeDefaultDescription
valuestring-The value of the accordion item.
disabledboolean-the accordion item will be disabled or not.
childrenReact.ReactNode | ((expanded: boolean) => React.ReactNode)-children of accordion item
Data attributeValues
[data-state]"open" | "closed"
[data-disabled]Visible when disabled

AccordionHeader

This item switches the expand/collapse state of the accordion item. This item has a titled element.

Data attributeValues
[data-state]"open" | "closed"
[data-disabled]Visible when disabled

AccordionContent

Contains the collapsible content for an item.

Data attributeValues
[data-state]"open" | "closed"
[data-disabled]Visible when disabled

AccordionArrowIcon

Down arrow icon rotating based on expand/collapse state.

Examples

Expanded by defaultValue

const DefaultValue = () => {
return (
<Accordion.Root defaultValue="item2">
<Accordion.Item value="item1">
<Accordion.Header>
<div style={{ flex: '1 1 0%' }}>Panel Title1</div>
<Accordion.ArrowIcon />
</Accordion.Header>
<Accordion.Content>Content1</Accordion.Content>
</Accordion.Item>
<Accordion.Item value="item2">
<Accordion.Header>
<div style={{ flex: '1 1 0%' }}>Panel Title2</div>
<Accordion.ArrowIcon />
</Accordion.Header>
<Accordion.Content>Content2</Accordion.Content>
</Accordion.Item>
</Accordion.Root>
);
};
render(<DefaultValue />);
Next
DocsMelioUI
Copyright © Ahn Co. All rights reserved.