Components
Accordion
The accordion component lets users show and hide small sections of related content on a page.
- Status
- Official
Contents
Contents
HTML
<div class="tna-accordion" data-single-open-item="false" data-module="tna-accordion">
<div class="tna-accordion__item" data-isopen="false">
<h3 class="tna-accordion__heading tna-heading-s">
Discovery
</h3>
<div class="tna-accordion__body" id="accordion-demo-content-1">
<p>Lorem ipsum</p>
</div>
</div>
<div class="tna-accordion__item" data-isopen="false">
<h3 class="tna-accordion__heading tna-heading-s">
Alpha
</h3>
<div class="tna-accordion__body" id="accordion-demo-content-2">
<p>Lorem ipsum</p>
</div>
</div>
<div class="tna-accordion__item" data-isopen="false">
<h3 class="tna-accordion__heading tna-heading-s">
Private beta
</h3>
<div class="tna-accordion__body" id="accordion-demo-content-3">
<p>Lorem ipsum</p>
</div>
</div>
<div class="tna-accordion__item" data-isopen="false">
<h3 class="tna-accordion__heading tna-heading-s">
Public beta
</h3>
<div class="tna-accordion__body" id="accordion-demo-content-4">
<p>Lorem ipsum</p>
</div>
</div>
<div class="tna-accordion__item" data-isopen="false">
<h3 class="tna-accordion__heading tna-heading-s">
Live
</h3>
<div class="tna-accordion__body" id="accordion-demo-content-5">
<p>Lorem ipsum</p>
</div>
</div>
</div>
Nunjucks
Nunjucks options
| Name | Type | Description |
|---|---|---|
| itemHeadingLevel | number |
Required. The heading level which represents an element from |
| itemHeadingSize | string |
The physical size of the accordion item titles ( Default value: |
| items | array |
Required. The sections within the accordion. |
| id | string |
Required. A unique ID for the accordion group. |
| singleOpenItem | boolean |
If Default value: |
| toggleAllButton | object |
Allows the user to open or close all sections. |
| classes | string |
Classes to add to the accordion. |
| attributes | object |
HTML attributes (for example data attributes) to add to the accordion. |
| Name | Type | Description |
|---|---|---|
| title | string |
Required. The heading of each accordion section. |
| body | string |
The HTML for the main body of the accordion item. Not displayed if |
| text | string |
The text for the accordion item which will be inserted into a |
| open | boolean |
If Default value: |
| Name | Type | Description |
|---|---|---|
| enabled | boolean |
Required. If Default value: |
| openAllLabel | string |
The label for the button when all sections are closed. Default value: |
| closeAllLabel | string |
The label for the button when all sections are open. Default value: |
{% from "nationalarchives/components/accordion/macro.njk" import tnaAccordion %}
{{ tnaAccordion({
itemHeadingLevel: 3,
items: [
{
title: "Discovery",
text: "Lorem ipsum"
},
{
title: "Alpha",
text: "Lorem ipsum"
},
{
title: "Private beta",
text: "Lorem ipsum"
},
{
title: "Public beta",
text: "Lorem ipsum"
},
{
title: "Live",
text: "Lorem ipsum"
}
],
id: "accordion-demo"
}) }}
Jinja
Important information
{% from "components/accordion/macro.html" import tnaAccordion %}
{{ tnaAccordion({
"itemHeadingLevel": 3,
"items": [
{
"title": "Discovery",
"text": "Lorem ipsum"
},
{
"title": "Alpha",
"text": "Lorem ipsum"
},
{
"title": "Private beta",
"text": "Lorem ipsum"
},
{
"title": "Public beta",
"text": "Lorem ipsum"
},
{
"title": "Live",
"text": "Lorem ipsum"
}
],
"id": "accordion-demo"
}) }}
Open and close all
Customise with toggleAllButton to add an extra option to show or hide all accordion items.
Contents
HTML
<div class="tna-accordion" data-single-open-item="false" data-module="tna-accordion">
<button class="tna-accordion__toggle-all" type="button" data-open-all-label="Show all sections" data-close-all-label="Hide all sections" hidden></button>
<div class="tna-accordion__item" data-isopen="false">
<h3 class="tna-accordion__heading tna-heading-s">
Discovery
</h3>
<div class="tna-accordion__body" id="accordion-demo-content-1">
<p>Lorem ipsum</p>
</div>
</div>
<div class="tna-accordion__item" data-isopen="false">
<h3 class="tna-accordion__heading tna-heading-s">
Alpha
</h3>
<div class="tna-accordion__body" id="accordion-demo-content-2">
<p>Lorem ipsum</p>
</div>
</div>
<div class="tna-accordion__item" data-isopen="false">
<h3 class="tna-accordion__heading tna-heading-s">
Private beta
</h3>
<div class="tna-accordion__body" id="accordion-demo-content-3">
<p>Lorem ipsum</p>
</div>
</div>
<div class="tna-accordion__item" data-isopen="false">
<h3 class="tna-accordion__heading tna-heading-s">
Public beta
</h3>
<div class="tna-accordion__body" id="accordion-demo-content-4">
<p>Lorem ipsum</p>
</div>
</div>
<div class="tna-accordion__item" data-isopen="false">
<h3 class="tna-accordion__heading tna-heading-s">
Live
</h3>
<div class="tna-accordion__body" id="accordion-demo-content-5">
<p>Lorem ipsum</p>
</div>
</div>
</div>
Nunjucks
Nunjucks options
| Name | Type | Description |
|---|---|---|
| itemHeadingLevel | number |
Required. The heading level which represents an element from |
| itemHeadingSize | string |
The physical size of the accordion item titles ( Default value: |
| items | array |
Required. The sections within the accordion. |
| id | string |
Required. A unique ID for the accordion group. |
| singleOpenItem | boolean |
If Default value: |
| toggleAllButton | object |
Allows the user to open or close all sections. |
| classes | string |
Classes to add to the accordion. |
| attributes | object |
HTML attributes (for example data attributes) to add to the accordion. |
| Name | Type | Description |
|---|---|---|
| title | string |
Required. The heading of each accordion section. |
| body | string |
The HTML for the main body of the accordion item. Not displayed if |
| text | string |
The text for the accordion item which will be inserted into a |
| open | boolean |
If Default value: |
| Name | Type | Description |
|---|---|---|
| enabled | boolean |
Required. If Default value: |
| openAllLabel | string |
The label for the button when all sections are closed. Default value: |
| closeAllLabel | string |
The label for the button when all sections are open. Default value: |
{% from "nationalarchives/components/accordion/macro.njk" import tnaAccordion %}
{{ tnaAccordion({
itemHeadingLevel: 3,
items: [
{
title: "Discovery",
text: "Lorem ipsum"
},
{
title: "Alpha",
text: "Lorem ipsum"
},
{
title: "Private beta",
text: "Lorem ipsum"
},
{
title: "Public beta",
text: "Lorem ipsum"
},
{
title: "Live",
text: "Lorem ipsum"
}
],
id: "accordion-demo",
toggleAllButton: {
enabled: true
}
}) }}
Jinja
Important information
{% from "components/accordion/macro.html" import tnaAccordion %}
{{ tnaAccordion({
"itemHeadingLevel": 3,
"items": [
{
"title": "Discovery",
"text": "Lorem ipsum"
},
{
"title": "Alpha",
"text": "Lorem ipsum"
},
{
"title": "Private beta",
"text": "Lorem ipsum"
},
{
"title": "Public beta",
"text": "Lorem ipsum"
},
{
"title": "Live",
"text": "Lorem ipsum"
}
],
"id": "accordion-demo",
"toggleAllButton": {
"enabled": True
}
}) }}