UI Toolbox logoUI Toolbox
Support

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 checkboxesAn 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, and the turn of its arrow. True (the default).
AnimationDuration (animation-duration) The time of the height animation, in milliseconds. Default 180. 0 opens and closes a section at once.
AnimationEasing (animation-easing) The curve of the height animation, one of the easing curves. Default OutCubic. With OutBack or OutElastic, a section that opens grows past its height and comes back.
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.unity-toggle .unity-toggle__input .unity-foldout__checkmark The arrow: a chevron of two borders. rotate is -45deg (right) on a closed section and 45deg (down) on an open section, with a rotate transition. An override of rotate, the size or the borders needs this full selector: a shorter one has less specificity than the rule of the control and the Unity theme wins over it.
tb-accordion--instant On the accordion when a section opens or closes with no animation. The arrow has a transition-duration of 0.
Custom property Description
--tb-accordion-arrow-color The color of the arrow. Default var(--tb-color-text-muted). Set it on the accordion, or on a class of the accordion: the accordion declares the property itself, so a value on a parent does not reach the arrow.
.tb-accordion > .unity-foldout > .unity-foldout__toggle {
    background-color: var(--tb-color-surface-alt);
}
.bestiary { --tb-accordion-arrow-color: #cdb27a; }

The AccordionDemo scene shows a help page of questions, a quest journal that tracks the open quest, a settings screen with several open sections and a bestiary in a game skin of wood and parchment.