Accordion
A component that allows you to group content into collapsible sections.
Usage
The Accordion component allows users to expand and collapse content sections by clicking on the header, allowing for a space-efficient and organized way to present information.
Anatomy
- Header: The clickable section title that users interact with to expand or collapse the content.
- Content Area: The area that expands or collapses, revealing or hiding additional information when the header is clicked.
Related
Properties
Property | Type | Description |
---|---|---|
children | array | An array with the component ID of all components belonging to the group. Enum: "Paragraph" | "Button" |
textResourceBindings.title | string | Clickable section title |
Configuration
Add component
You can add a component in Altinn Studio Designer by dragging it from the left-side panel to the middle page area. Selecting the component brings up its configuration panel on the right-hand side.
Settings in Altinn Studio Designer
Property settings available in Altinn Studio Designer.
children
is required and must be added manually.- Komponent-ID (
id
): Automatically generated component ID (editable).
Corresponding settings in the page’s JSON file.
App/ui/layouts/{page}.json
...
{
"data": {
"layout": [
{
"id": "Accordion-3uoJMS",
"type": "Accordion"
}
]
}
}
Add title and elements
textResourceBindings.title
The title for the Accordion can be added as text directly or referenced via a text key to a text resource.
children
Specify which components you want to expand by adding their IDs to an array under children
.
The following types can be added to an Accordion
:
Paragraph
Button
Example
Accordion with a paragraph and a button as child elements.
App/ui/layouts/{page}.json
...
{
"data": {
"layout": [
{
"id": "Accordion-3uoJMS",
"type": "Accordion",
"textResourceBindings": {
"title": "Lorem ipsum"
},
"children": ["lorem-ipsum", "ok-button"]
},
{
"id": "lorem-ipsum",
"type": "Paragraph",
"textResourceBindings": {
"title": "Paragraph.loremIpsum1"
},
"dataModelBindings": {}
},
{
"id": "ok-button",
"type": "Button",
"dataModelBindings": {},
"textResourceBindings": {
"title": "OK"
}
}
]
}
}
Heading Level
The default heading level is 2
. To change it, add the headingLevel
property as shown in the code example below.
headingLevel
can take values of 2 | 3 | 4 | 5 | 6
.
App/ui/layouts/{page}.json
...
{
"data": {
"layout": [
{
"id": "Accordion-3uoJMS",
"type": "Accordion",
"textResourceBindings": {
"title": "Lorem ipsum"
},
"children": ["lorem-ipsum", "ok-button"],
"headingLevel": 3
},
...
]
}
}