Skip to content

Accordion

Accordion components are Layout Fields that organize collapsable information.

accordion.json
{
"form": {
"uid": "",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "tab5",
"kind": "layout",
"widget": "accordion",
"props": {
"sections": [
{ "label": "Personal Information", "uid": "section1" },
{ "label": "Shipping Address", "uid": "section2" },
{ "label": "Billing Address", "uid": "section3" }
]
},
"children": [
{
"uid": "section1",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "shoppingCart.firstName"
}
]
},
{
"uid": "section2",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "shoppingCart.shippingAddress"
}
]
},
{
"uid": "section3",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "shoppingCart.billingAddress"
}
]
}
]
}
]
}
}

Use this props to customize your Accordion component.

proptypevalue
singleOpenbooleanA boolean value to have only one active section at a time
defaultOpenobjectAn object with a dictionary of sections with boolean values to display sections on start
sectionsarrayMANDATORY An array of objects with title and a target uid in the children array

Use the property singleOpen to display only one section. When true Accordion component will collapse other sections if a new section has been selected.

accordion.json
{
"form": {
"uid": "",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "tab5",
"kind": "layout",
"widget": "accordion",
"props": {
"singleOpen": true,
"sections": [
{ "label": "Personal Information", "uid": "section1" },
{ "label": "Shipping Address", "uid": "section2" },
{ "label": "Billing Address", "uid": "section3" }
]
},
"children": [
{
"uid": "section1",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "shoppingCart.firstName"
}
]
},
{
"uid": "section2",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "shoppingCart.shippingAddress"
}
]
},
{
"uid": "section3",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "shoppingCart.billingAddress"
}
]
}
]
}
]
}
}

Use the property defaultOpen to open one or more sections on start.

accordion.json
{
"form": {
"uid": "",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "tab5",
"kind": "layout",
"widget": "accordion",
"props": {
"defaultOpen": {
"section1": true,
"section2": true
},
"sections": [
{ "label": "Personal Information", "uid": "section1" },
{ "label": "Shipping Address", "uid": "section2" },
{ "label": "Billing Address", "uid": "section3" }
]
},
"children": [
{
"uid": "section1",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "shoppingCart.firstName"
}
]
},
{
"uid": "section2",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "shoppingCart.shippingAddress"
}
]
},
{
"uid": "section3",
"kind": "layout",
"widget": "stack",
"children": [
{
"uid": "",
"kind": "control",
"widget": "textinput",
"path": "shoppingCart.billingAddress"
}
]
}
]
}
]
}
}

Accordions can be styled as explained in the Styling Guide.

Following you will find a list with the CSS Variables and a quick description of what you will style.

CSS VariableDescription
--gui-space-gapAccordion margins
--gui-paddingButton and Section padding
--gui-color-borderButton and Section border color
--gui-color-bgButton and Section background color
--gui-color-fgButton and Section text color

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

accordion.html
<gui-accordion>
<div class="gui-accordion__section">
<button type="button" tabindex="1" class="active" aria-expanded="true">
Label<span class="gui-accordion__icon"></span>
</button>
<section class="gui-field" role="region"></section>
</div>
</gui-accordion>