Accordion

Accordion is used for showing and hiding content in collapsible sections. Only one section can be open at a time.

Basic Example

FAQ-style accordion


const { default: Accordion } = await import('/components/data-display/accordion.js');

const { tags, $ } = Lightview;

const faq = [
    { q: 'What is Lightview?', a: 'A lightweight reactive UI library.' },
    { q: 'Does it support TypeScript?', a: 'Yes! Full TypeScript support.' },
    { q: 'How do I get started?', a: 'Check out our Getting Started guide!' }
];

const accordion = Accordion({},
    ...faq.map((item, i) => 
        Accordion.Item({ name: 'faq', checked: i === 0 },
            Accordion.Title({}, item.q),
            Accordion.Content({}, item.a)
        )
    )
);

$('#demo').insert(accordion);

Plus/Minus Icon

Accordion with plus/minus toggle icon


const { default: Accordion } = await import('/components/data-display/accordion.js');

const { tags, $ } = Lightview;

const sections = [
    { title: '📦 Shipping', content: 'Free shipping on orders over $50.' },
    { title: '🔄 Returns', content: '30-day return policy for unused items.' },
    { title: '💳 Payment', content: 'We accept all major credit cards.' }
];

const accordion = Accordion({ join: true },
    ...sections.map((item, i) => 
        Accordion.Item({ name: 'info', icon: 'plus', join: true, checked: i === 0 },
            Accordion.Title({}, item.title),
            Accordion.Content({}, item.content)
        )
    )
);

$('#demo').insert(accordion);

Props

Prop Type Default Description
join boolean false Use connected/joined style

Accordion.Item Props

Prop Type Default Description
name string 'accordion' Radio group name (only one opens at a time)
icon string 'arrow' 'arrow' | 'plus'
checked boolean false Initially open
join boolean false Use joined styling

Arrow Icon (Default)

Click to open this one
Content for section one.
Click to open this one
Content for section two.

Plus/Minus Icon

Click me to show/hide
Hidden content revealed!
For more examples, see the DaisyUI Accordion documentation.