On this page Expansion Panel Expansion Panel

The @m3e/expansion-panel package provides components for organizing content in collapsible sections and coordinated groups. It includes the following components:

Installation
npm i @m3e/expansion-panel
Usage

This section outlines usage examples and configuration guidance for the components in this package.

Standalone panels

You can use a standalone m3e-expansion-panel to present a collapsible details-summary section. Use the header slot to specify the title of a panel and use the default slot for its content.

Panel header Panel contents
<m3e-expansion-panel>
  <span slot="header">Panel header</span>
  Panel contents
</m3e-expansion-panel>

Use the open attribute to control whether a panel is open (expanded).

Panel header Panel contents
<m3e-expansion-panel open>
  <span slot="header">Panel header</span>
  Panel contents
</m3e-expansion-panel>
Toggles

You can change the toggle position and direction using the toggle-position and toggle-direction attributes. Supported positions include: before and after (default). Supported directions include vertical (default) and horizontal.

Panel header Panel contents
<m3e-expansion-panel toggle-position="before" toggle-direction="horizontal">
  <span slot="header">Panel header</span>
  Panel contents
</m3e-expansion-panel>

Use the hide-toggle attribute to hide the toggle.

Panel header Panel contents
<m3e-expansion-panel hide-toggle>
  <span slot="header">Panel header</span>
  Panel contents
</m3e-expansion-panel>
Accordion

Use a m3e-accordion to create a coordinated group of panels.

Panel 1 I am content for the first panel Panel 2 I am content for the second panel Panel 3 I am content for the third panel
<m3e-accordion>
  <m3e-expansion-panel open>
    <span slot="header">Panel 1</span>
    I am content for the first panel
  </m3e-expansion-panel>
  <!-- Additional panels omitted for brevity -->
</m3e-accordion>

By default, only one panel can be open at a time. Use the multi attribute to allow multiple panels to be open at the same time.

Panel 1 I am content for the first panel Panel 2 I am content for the second panel Panel 3 I am content for the third panel
<m3e-accordion multi>
  <m3e-expansion-panel open>
    <span slot="header">Panel 1</span>
    I am content for the first panel
  </m3e-expansion-panel>
  <!-- Additional panels omitted for brevity -->
</m3e-accordion>
Accessibility

Expansion panels imitate the experience of the native detail and summary elements. Internally, a panel's header is given ARIA role="button" and the aria-controls attribute with the panel's internal content wrapper's ID. Additionally, the internal header's aria-expanded attribute reflects the expanded state of the panel.

Because expansion panel headers are buttons, avoid adding interactive controls in the header slot, including buttons and anchors.

Native module support

This package uses JavaScript Modules. To use it directly in a browser without a bundler, use a module script similar to the following.

<script type="module" src="/node_modules/@m3e/expansion-panel/dist/index.js"></script>

In addition, you must use an import map to include dependencies.

<script type="importmap">
  {
    "imports": {
      "lit": "https://cdn.jsdelivr.net/npm/lit@3.3.0/+esm",
      "@m3e/core": "/node_modules/@m3e/core/dist/index.js"
    }
  }
</script>

For production, use index.min.js for faster load times.

API

This package includes a Custom Elements Manifest (custom-elements.json), which documents the properties, attributes, slots, events and CSS custom properties of each component.

You can explore the API below, or integrate the manifest into your own tooling.