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.


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. |
- Each child
Foldoutis a section. To open or close a section from code, set itsvalue. - A
Foldoutis open by default. When the accordion attaches to a panel, it keeps the first open section and closes the other sections. Setvalue="false"on eachFoldoutto start with all sections closed. - A click on a header opens its section. Enter, Space and the submit button of a gamepad do the same for the header with the focus.
- Tab and the up and down keys of the keyboard or a gamepad move between the headers. Left closes the section of the focused header and right opens it.
- The header with the focus shows the focus border of the workspace.
- A
Foldoutor aTogglein the content of a section is not a section. It does not close the other sections. - A section opens and closes with a short height animation: 180 ms on the
OutCubiccurve by default, set byAnimationDurationandAnimationEasing. The section slides and clips its content: the content keeps its height, so its text does not squash. At the end the section has its automatic height again, so a later change of the content resizes the section. Setanimate="false"to open and close at once. WithAnimationsEnabledoff on the workspace, there is no animation. - The arrow at the left of each header points right on a closed section and down on an open section. It turns in
--tb-animation-duration-faston theease-out-cubiccurve. With no height animation (animate="false",animation-duration="0"orAnimationsEnabledoff), the accordion has thetb-accordion--instantclass and the arrow turns at once.
Tips:
- Use
multiple="true"for a settings page, where the user compares sections. - Use the default mode for a list of questions, where one answer shows at a time.
- With
collapsible="true", setvalue="false"on eachFoldoutfor a list that starts closed. - Keep the header text short. A long header does not wrap.
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.