Skip to content

Accordion

Accordion widgets are Layout Fields that allow users to toggle the visibility of content sections. They are ideal for grouping related fields and saving vertical space in complex forms.

accordion.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.layouts.accordion([
{
label: 'Personal Information',
uid: 'personal',
children: [
gui.inputs.textInput('name', {
label: 'Full Name',
}),
],
},
{
label: 'Account Settings',
uid: 'account',
children: [
gui.inputs.textInput('email', {
label: 'Email Address',
}),
],
},
], {
defaultOpen: {
personal: true,
},
uid: 'accordion_basic',
}),
];

Use these props to customize your Accordion widget.

proptypedescription
sectionsarrayRequired. Array of section definitions: { label: string, uid: string }
singleOpenbooleanIf true, only one section can be open at a time. Defaults to false
defaultOpenobjectObject mapping section uids to boolean state (e.g., { "section_1": true })
renderModestringEither 'all' (renders hidden sections in DOM) or 'activeOnly' (renders only open sections). Defaults to 'all'

Use the singleOpen property to ensure that opening one section automatically closes others.

accordion.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.layouts.accordion([
{
label: 'First Section',
uid: 'sec1',
children: [
gui.inputs.textInput('f1', {
label: 'Field 1',
}),
],
},
{
label: 'Second Section',
uid: 'sec2',
children: [
gui.inputs.textInput('f2', {
label: 'Field 2',
}),
],
},
], {
singleOpen: true,
uid: 'accordion_single',
}),
];

Accordions can be styled as explained in the Styling Guide.

Following you will find a list with the CSS Variables used to style the accordion.

CSS VariableDescription
--gui-bg-defaultBackground color for sections and buttons
--gui-border-defaultBorder color for sections and buttons
--gui-text-defaultText color for labels
--gui-space-3Padding inside sections and buttons

This is the anatomy of the Accordion Widget in case you want to use your CSS styles.

accordion-anatomy.html
<div class="gui-accordion">
<div class="gui-widget" id="accordion_uid">
<div class="gui-accordion__section">
<button type="button" class="active" id="accordion_button_personal" aria-expanded="true">
Personal Information
<span class="gui-accordion__icon"></span>
</button>
<section role="region" id="accordion_section_personal" aria-labelledby="accordion_button_personal">
<!-- Content for Personal Information -->
<div class="gui-widget">
<!-- Child widgets render here -->
</div>
</section>
</div>
<div class="gui-accordion__section">
<button type="button" id="accordion_button_account" aria-expanded="false">
Account Settings
<span class="gui-accordion__icon"></span>
</button>
<section role="region" id="accordion_section_account" aria-labelledby="accordion_button_account" hidden>
<!-- Content for Account Settings -->
</section>
</div>
</div>
</div>