UI Toolbox logoUI Toolbox

Accordion

An Accordion is a stack of sections where one section is open at a time. Each section is a Unity Foldout: its text is the header, and its children are the content.

An accordion with four sections. The first section is open and shows a text and three checkboxes

How to make an accordion for a list of questions:

<tb:Accordion name="faq">
    <ui:Foldout text="How do I save a game?">
        <ui:Label text="The game saves at each checkpoint." />
    </ui:Foldout>
    <ui:Foldout text="How do I change the keys?">
        <ui:Label text="Open Settings, then Controls." />
    </ui:Foldout>
    <ui:Foldout text="How do I play with a friend?">
        <ui:Label text="Open the Friends window and send an invite." />
    </ui:Foldout>
</tb:Accordion>
var faq = root.Q<Accordion>("faq");
faq.Opened += section => Debug.Log($"Opened: {section.text}");
faq.Q<Foldout>().value = true;
Member Description
Multiple (multiple) Lets more than one section be open. False (the default) closes the other sections when one opens.
Collapsible (collapsible) Lets the user close the open section, so that no section is open. False (the default) keeps one section open. It has no effect with Multiple.
Animate (animate) Animates the height of a section that opens or closes. True (the default).
Opened Raised after a section opened, with the Foldout of the section.

Tips:

Styling

Class Element
tb-accordion The control: a --tb-color-border border with --tb-radius-md corners.
tb-accordion > .unity-foldout A section. It has a --tb-color-border line under it.
tb-accordion > .unity-foldout > .unity-foldout__toggle The header: bold text, --tb-color-surface-hover on hover.
tb-accordion > .unity-foldout > .unity-foldout__content The content, with --tb-spacing-md padding at the left, the right and the bottom.
.tb-accordion > .unity-foldout > .unity-foldout__toggle { background-color: var(--tb-color-surface-alt); }