Zubra UI
Code for
GitHub

accordion-panel

A section that opens and closes, on the native <details>: the browser does the keyboard (Enter and Space on the heading), the find-in-page opening and the announcements. Panels with the same group form an accordion where one is open at a time (<details name>). open is two-way.

The component's code is written into your project. It's yours to read and change, with no package to update.

Try it: events appear here (openchange).

Source: accordion-panel.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/accordion-panel.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/accordion-panel.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/accordion-panel.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/accordion-panel.json
One file, no dependencies (3.6 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/accordion-panel.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/accordion-panel.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/accordion-panel.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/accordion-panel.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/accordion-panel.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/accordion-panel.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/accordion-panel.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/accordion-panel.json
No build: a script tag, straight from this site
HTML
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/accordion-panel.js"></script>

The compiled install writes src/components/zubra/accordion-panel.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.

Usage

index.html
<accordion-panel heading="What does &quot;copy in&quot; mean?" group="faq">
  <p>The component's code is written into your project. It's yours to read and change, with no package to update.</p>
</accordion-panel>

<script type="module">
  import './components/zubra/accordion-panel.js';

  const element = document.querySelector('accordion-panel');
  element.open = true;
  element.addEventListener('openchange', (event) => console.log('openchange', event.detail));
</script>
Example.jsx
import './components/zubra/accordion-panel.js';

const open = true;

export function AccordionPanelExample() {
  return (
    <accordion-panel
      heading="What does &quot;copy in&quot; mean?"
      group="faq"
      open={open}
      onopenchange={(event) => console.log('openchange', event.detail)}
    >
      <p>The component's code is written into your project. It's yours to read and change, with no package to update.</p>
    </accordion-panel>
  );
}
Example.vue
<script setup>
import './components/zubra/accordion-panel.js';
const open = true;
const onOpenchange = (event) => console.log('openchange', event.detail);
</script>

<template>
  <accordion-panel
    heading="What does &quot;copy in&quot; mean?"
    group="faq"
    :open.prop="open"
    @openchange="onOpenchange"
  >
    <p>The component's code is written into your project. It's yours to read and change, with no package to update.</p>
  </accordion-panel>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/accordion-panel.js';
  const open = true;
</script>

<accordion-panel
  heading="What does &quot;copy in&quot; mean?"
  group="faq"
  {open}
  onopenchange={(event) => console.log('openchange', event.detail)}
>
  <p>The component's code is written into your project. It's yours to read and change, with no package to update.</p>
</accordion-panel>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/accordion-panel.js';

@Component({
  selector: 'app-accordion-panel-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <accordion-panel
      heading="What does &quot;copy in&quot; mean?"
      group="faq"
      [open]="open"
      (openchange)="onOpenchange($event)"
    >
      <p>The component's code is written into your project. It's yours to read and change, with no package to update.</p>
    </accordion-panel>
  `,
})
export class AccordionPanelExample {
  open = true;

  onOpenchange(event: Event) {
    console.log('openchange', (event as CustomEvent).detail);
  }
}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
openbooleanfalse
headingstring""
groupstring""
Events
EventWhen
openchangeopen changed; detail is the new value.
Slots
SlotFor
(default)The panel's content.
headingIts heading (defaults to heading).

Size

1.1 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 17.3 KB.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour