Docs

Documentation versions (currently viewingVaadin 14)

You are viewing documentation for an older Vaadin version. View latest documentation

Accordion

Accordion is a vertically stacked set of expandable panels. It reduces clutter and helps maintain the user’s focus by showing only the relevant content at a time.

Open in a
new tab
Accordion accordion = new Accordion();

Span name = new Span("Sophia Williams");
Span email = new Span("sophia.williams@company.com");
Span phone = new Span("(501) 555-9128");

VerticalLayout personalInformationLayout = new VerticalLayout(name, email, phone);
personalInformationLayout.setSpacing(false);
personalInformationLayout.setPadding(false);

accordion.add("Personal information", personalInformationLayout);

Anatomy

Accordion consists of stacked panels, each composed of two parts: a summary and a content area. Only one panel can be expanded at a time. (The Details component can be used to allow multiple simultaneously expanded sections.)

Summary

The summary is the part that is always visible, and typically describes the contents, for example, with a title. Clicking on the summary toggles the content area’s visibility.

The summary supports rich content and can contain any component. This can be utilized, for example, to display the status of the corresponding content.

Open in a
new tab
AccordionPanel customDetailsPanel = accordion.add(CUSTOMER_DETAILS,  customerDetailsFormLayout);
customDetailsPanel.addOpenedChangeListener(e -> {
    if(e.isOpened()) {
        customDetailsPanel.setSummaryText(CUSTOMER_DETAILS);
    } else if(personBinder.getBean() != null) {
        Person personValues = personBinder.getBean();
        customDetailsPanel.setSummary(createSummary(CUSTOMER_DETAILS,
            personValues.getFirstName() + " " + personValues.getLastName(),
            personValues.getEmail(),
            personValues.getAddress() != null ? personValues.getAddress().getPhone() : ""
        ));
    }
});

Content

This is the collapsible part of a panel. It can contain any component. When the content area is collapsed, the content is invisible and inaccessible by keyboard or screen reader.

Open in a
new tab
Accordion accordion = new Accordion();

accordion.add("Analytics", createContent(
    createStyledAnchor("#", "Dashboard"),
    createStyledAnchor("#", "Reports"),
    createStyledAnchor("#", "Data sources")
));

Theme Variants

Accordion has three theme variants: filled, small and reverse. Set the theme attribute separately for each panel, not on Accordion itself. Theme names can be combined with each other, for example, all three themes filled, small, and reverse can be applied to a panel.

Filled Panels

The filled theme variant makes the panel’s boundaries visible, which helps tie its content together visually and distinguishes it from the surrounding UI.

Open in a
new tab
Accordion accordion = new Accordion();
AccordionPanel personalInfoPanel = accordion.add("Personal information", personalInformationLayout);
personalInfoPanel.addThemeVariants(DetailsVariant.FILLED);

Small Panels

Use the small theme variant for compact UIs.

Open in a
new tab
AccordionPanel paymentPanel = accordion.add("Payment", paymentLayout);
paymentPanel.addThemeVariants(DetailsVariant.SMALL);

Reverse Panels

The reverse theme variant places the toggle icon after the summary contents, which can be useful for visually aligning the summary with other content.

Open in a
new tab
AccordionPanel paymentPanel = accordion.add("Payment", paymentLayout);
paymentPanel.addThemeVariants(DetailsVariant.REVERSE);

Disabled Panels

Accordion panels can be disabled to prevent them from being expanded or collapsed. Details can be disabled to prevent them from being expanded or collapsed. Components inside a disabled expanded panel are automatically disabled as well.

Open in a
new tab
Accordion accordion = new Accordion();
AccordionPanel billingAdressPanel = accordion.add("Billing address", billingAddressLayout);
billingAdressPanel.setEnabled(false);

Best Practices

  • Accordions are suitable when users need to focus on smaller pieces of content at a time. However, when the whole content is relevant to the user to make a decision, Accordions should be avoided.

  • Contents that are logically linked should be grouped together in one panel.

  • Accordions are better suited for long labels compared to Tabs. However, Accordions can feel “jumpy” as panels are toggled (if there are a lot of panels or the panel content is long).

  • Details can be used instead of Accordion when there is a need to see content from multiple panels simultaneously.

  • Accordions can be used to break a complex form into smaller step-by-step sections.

Component Usage recommendations

Details

Single collapsible panel.

Tabs

Component for organizing and grouping content into navigable sections.

A9679DB2-C376-4307-B391-0AEFF5F611FD