Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Accordion

Accordion organizes content into expandable sections.

When To Use It

Use Accordion when you need to progressively disclose grouped content while keeping the interface compact, for example settings categories, FAQs, or inspector panels.

Constructing an Accordion

use vizia::prelude::*;

#[derive(Clone)]
struct Section {
    title: String,
    body: String,
}

let sections = Signal::new(vec![
    Section { title: "General".into(), body: "General settings".into() },
    Section { title: "Audio".into(), body: "Audio settings".into() },
]);

Accordion::new(cx, sections, |_, _, section| {
    AccordionPair::new(
        move |cx| Label::new(cx, section.title.clone()),
        move |cx| Label::new(cx, section.body.clone()),
    )
});

Programmatically control which sections are open:

Accordion::new(cx, sections, |_, _, section| {
    AccordionPair::new(
        move |cx| Label::new(cx, section.title.clone()),
        move |cx| Label::new(cx, section.body.clone()),
    )
})
.open(open_sections);

Accordion Modifiers

ModifierTypeDescriptionDefault
openimpl Res<Vec<usize>>Controls which section indices are open.[]
on_toggleFn(&mut EventContext, usize, bool)Called when a section is toggled, with the section index and desired open state.

Components and Styling

SelectorDescription
accordionRoot accordion element.

Accordion composes Collapsible rows and Divider separators internally.

Accessibility

  • Keep section headers descriptive so collapsed content remains understandable.
  • Ensure header controls are keyboard reachable through normal tab order.

Keyboard Interaction

Accordion keyboard behavior follows the focusable controls used for each section header (typically button-like trigger rows):

KeyAction
Tab / Shift+TabMove focus between accordion headers and other focusable controls.
ArrowDownMove focus to the next accordion header (wraps from last to first).
ArrowUpMove focus to the previous accordion header (wraps from first to last).
HomeMove focus to the first accordion header.
EndMove focus to the last accordion header.
Enter / SpaceToggle the focused section open or closed.