This documentation is under construction. Pages can be missing or change at any time. Follow it on GitHub.

Skip to content

Accordion

A set of collapsible panels with headings.

Examples#

Open multiple panels#

You can set up the accordion to allow multiple panels to be open at the same time using the multiple prop.

Hidden until found#

The hiddenUntilFound prop hides closed panels with hidden="until-found" so the browser can search their contents and reveal the matching panel automatically. It can be set on each AccordionPanel, or once on Accordion to apply to all panels.

To try it, press Ctrl+F (Cmd+F on macOS) and search for “restocking”—the browser opens the closed panel containing the match. When hiddenUntilFound is enabled, closed panels always remain in the DOM, which also makes their contents indexable by search engines.

Older browsers that don’t support hidden="until-found" keep panels hidden until their trigger opens them, and find-in-page skips over the contents.

API reference#

Import the components of the family:

use Phem\Ui\Accordion;
use Phem\Ui\AccordionItem;
use function Phem\Ui\{AccordionHeader, AccordionTrigger, AccordionPanel};

Accordion#

A list of sections that open and close: Base UI Accordion.Root, on the phem-accordion controller.

defaultValue lists the values of the open items. Give an id when the page has more than one accordion with the same item values: the ids of the triggers and the panels start with it.

PropTypeDefault
defaultValuearray[]
multipleboolfalse
disabledboolfalse
hiddenUntilFoundboolfalse
orientation'horizontal' | 'vertical'Orientation::Vertical
loopFocusbooltrue
rovingFocusboolfalse
id?stringnull
children?Htmlnull
...attrsarray[]

AccordionItem#

An item: a header with a trigger, and a panel. value names the item, and gives the ids of its parts.

PropTypeDefault
value (required)string—
disabledboolfalse
children?Htmlnull
...attrsarray[]

AccordionHeader#

The heading of an accordion item: an <h3> around its AccordionTrigger.

PropTypeDefault
children?Htmlnull
...restmixed—

AccordionTrigger#

The button that opens and closes the item. It has a plus icon that turns when the item is open.

PropTypeDefault
children?Htmlnull
...restmixed—

AccordionPanel#

The panel of the item. Its height animates with --accordion-panel-height. With hiddenUntilFound, this closed panel has hidden="until-found", as with the prop of the root.

PropTypeDefault
hiddenUntilFoundboolfalse
children?Htmlnull
...restmixed—

The source of the examples: examples/ui/Accordion.phem.

Phem
Esc
↑↓ to navigate↵ to openEsc to close