Skip to content

Accordion

Accordion components 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 { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
uid: 'accordion_basic',
kind: 'layout',
type: 'accordion',
props: {
sections: [
{
uid: 'personal',
label: 'Personal Information',
},
{
uid: 'account',
label: 'Account Settings',
},
],
defaultOpen: {
personal: true,
},
},
children: [
{
uid: 'personal',
kind: 'input',
type: 'textinput',
path: 'name',
label: 'Full Name',
},
{
uid: 'account',
kind: 'input',
type: 'textinput',
path: 'email',
label: 'Email Address',
},
],
},
],
});
accordion.json
{
"form": [
{
"uid": "accordion_basic",
"kind": "layout",
"type": "accordion",
"props": {
"sections": [
{ "uid": "personal", "label": "Personal Information" },
{ "uid": "account", "label": "Account Settings" }
],
"defaultOpen": { "personal": true }
},
"children": [
{
"uid": "personal",
"kind": "input",
"type": "textinput",
"path": "name",
"label": "Full Name"
},
{
"uid": "account",
"kind": "input",
"type": "textinput",
"path": "email",
"label": "Email Address"
}
]
}
]
}

Use these props to customize your Accordion component.

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 { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
uid: 'accordion_single',
kind: 'layout',
type: 'accordion',
props: {
sections: [
{
uid: 'sec1',
label: 'First Section',
},
{
uid: 'sec2',
label: 'Second Section',
},
],
singleOpen: true,
},
children: [
{
uid: 'sec1',
kind: 'input',
type: 'textinput',
path: 'f1',
label: 'Field 1',
},
{
uid: 'sec2',
kind: 'input',
type: 'textinput',
path: 'f2',
label: 'Field 2',
},
],
},
],
});
accordion.json
{
"form": [
{
"uid": "accordion_single",
"kind": "layout",
"type": "accordion",
"props": {
"sections": [
{ "uid": "sec1", "label": "First Section" },
{ "uid": "sec2", "label": "Second Section" }
],
"singleOpen": true
},
"children": [
{
"uid": "sec1",
"kind": "input",
"type": "textinput",
"path": "f1",
"label": "Field 1"
},
{
"uid": "sec2",
"kind": "input",
"type": "textinput",
"path": "f2",
"label": "Field 2"
}
]
}
]
}

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 Component 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>