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
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
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
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
<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
<accordion-panel heading="What does "copy in" 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>import './components/zubra/accordion-panel.js';
const open = true;
export function AccordionPanelExample() {
return (
<accordion-panel
heading="What does "copy in" 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>
);
}<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 "copy in" 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('-') } } }) --><script>
import './components/zubra/accordion-panel.js';
const open = true;
</script>
<accordion-panel
heading="What does "copy in" 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>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 "copy in" 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
| Property | Type | Default |
|---|---|---|
open | boolean | false |
heading | string | "" |
group | string | "" |
| Event | When |
|---|---|
openchange | open changed; detail is the new value. |
| Slot | For |
|---|---|
(default) | The panel's content. |
heading | Its 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.