This is the content for Writing well for the web.
This is the content for Writing well for the web.
The accordion component lets users show and hide sections of related content on a page.
This component is based on the GOV.UK Design System accordion component and is currently experimental because more research is needed to validate it. If using this component, please feed back any research findings to the Design System team.
This is the content for Writing well for the web.
This is the content for Writing well for specialists.
This is the content for Know your audience.
This is the content for How people read.
<%= render "govuk_publishing_components/components/accordion", {
items: [
{
heading: {
text: "Writing well for the web"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Writing well for the web.</p>")
},
data_attributes: {
ga4_event: "{\"event_name\":\"select_content\",\"type\":\"accordion\",\"text\":\"Writing well for the web\",\"index_section\":1,\"index_section_count\":4}"
}
},
{
heading: {
text: "Writing well for specialists"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Writing well for specialists.</p>")
},
data_attributes: {
ga4_event: "{\"event_name\":\"select_content\",\"type\":\"accordion\",\"text\":\"Writing well for specialists\",\"index_section\":2,\"index_section_count\":4}"
}
},
{
heading: {
text: "Know your audience"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Know your audience.</p>")
},
data_attributes: {
ga4_event: "{\"event_name\":\"select_content\",\"type\":\"accordion\",\"text\":\"Know your audience\",\"index_section\":3,\"index_section_count\":4}"
}
},
{
heading: {
text: "How people read"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for How people read.</p>")
},
data_attributes: {
ga4_event: "{\"event_name\":\"select_content\",\"type\":\"accordion\",\"text\":\"How people read\",\"index_section\":4,\"index_section_count\":4}"
}
}
]
} %>
This component incorporates components from the GOV.UK Design System:
The accordion must:
aria-controls
attributeSection headings must use a button element so that users:
When CSS and / or JavaScript is unavailable, the component must:
Links in the component must:
This component uses the component wrapper helper. It accepts the following options and applies them to the parent element of the component. See the component wrapper helper documentation for more detail.
id
- accepts a string for the element ID attributedata_attributes
- accepts a hash of data attributesaria
- accepts a hash of aria attributesclasses
- accepts a space separated string of classes, these should not be used for styling and must be prefixed with js-
role
- accepts a space separated string of roleslang
- accepts a language attribute valueopen
- accepts an open attribute value (true or false)An id
for an individual accordion is optional as it’s automatically generated, but it can be supplied if a specific id
is required.
The id
must be unique across the domain of your service. This is because the open or closed state of individual instances of the accordion uses localStorage
to persist across page loads.
Used as an id
in the HTML for the accordion as a whole, and also as a prefix for the id
s of the section contents and the buttons that open them, so that those id
s can be the target of aria-control
attributes.
This is the content for Writing well for the web.
This is the content for Writing well for specialists.
This is the content for Know your audience.
This is the content for How people read.
<%= render "govuk_publishing_components/components/accordion", {
id: "with-supplied-id-thats-unique-across-the-domain",
items: [
{
heading: {
text: "Writing well for the web"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Writing well for the web.</p>")
}
},
{
heading: {
text: "Writing well for specialists"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Writing well for specialists.</p>")
}
},
{
heading: {
text: "Know your audience"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Know your audience.</p>")
}
},
{
heading: {
text: "How people read"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for How people read.</p>")
}
}
]
} %>
Adds a subheading below each section heading.
<%= render "govuk_publishing_components/components/accordion", {
items: [
{
heading: {
text: "Understanding agile project management"
},
summary: {
text: "Introductions, methods, core features."
},
content: {
html: sanitize("<ul class=\"govuk-list\"> <li> <a class=\"govuk-link\" href=\"#\">Agile and government services: an introduction</a> </li> <li> <a class=\"govuk-link\" href=\"#\">Agile methods: an introduction</a> </li> <li> <a class=\"govuk-link\" href=\"#\">Core principles of agile</a> </li> </ul>")
}
},
{
heading: {
text: "Working with agile methods"
},
summary: {
text: "Workspaces, tools and techniques, user stories, planning."
},
content: {
html: sanitize("<ul class=\"govuk-list\"> <li> <a class=\"govuk-link\" href=\"#\">Creating an agile working environment</a> </li> <li> <a class=\"govuk-link\" href=\"#\">Agile tools and techniques</a> </li> <li> <a class=\"govuk-link\" href=\"#\">Set up a team wall</a> </li> <li> <a class=\"govuk-link\" href=\"#\">Writing user stories</a> </li> <li> <a class=\"govuk-link\" href=\"#\">Planning in agile</a> </li> <li> <a class=\"govuk-link\" href=\"#\">Deciding on priorities</a> </li> <li> <a class=\"govuk-link\" href=\"#\">Developing a roadmap</a> </li> </ul>")
}
},
{
heading: {
text: "Governing agile services"
},
summary: {
text: "Principles, measuring progress, spending money."
},
content: {
html: sanitize("<ul class=\"govuk-list\"> <li> <a class=\"govuk-link\" href=\"#\">Governance principles for agile service delivery</a> </li> <li> <a class=\"govuk-link\" href=\"#\">Measuring and reporting progress</a> </li> <li> <a class=\"govuk-link\" href=\"#\">Spend controls: check if you need approval to spend money on a service</a> </li> <li> <a class=\"govuk-link\" href=\"#\">Spend controls: apply for approval to spend money on a service</a> </li> <li> <a class=\"govuk-link\" href=\"#\">Spend controls: the new pipeline process</a> </li> <li> <a class=\"govuk-link\" href=\"#\">Working across organisational boundaries</a> </li> </ul>")
}
},
{
heading: {
text: "Phases of an agile project"
},
summary: {
text: "Discovery, alpha, beta, live and retirement."
},
content: {
html: sanitize("<ul class=\"govuk-list\"> <li> <a class=\"govuk-link\" href=\"#\">How the discovery phase works</a> </li> <li> <a class=\"govuk-link\" href=\"#\">How the alpha phase works</a> </li> <li> <a class=\"govuk-link\" href=\"#\">How the beta phase works</a> </li> <li> <a class=\"govuk-link\" href=\"#\">How the live phase works</a> </li> <li> <a class=\"govuk-link\" href=\"#\">Retiring your service</a> </li> </ul>")
}
}
]
} %>
Disables GA4 tracking on the accordion. Tracking is enabled by default. This adds a data module and data-attributes with JSONs to the accordion. See the ga4-event-tracker documentation for more information.
This is the content for Writing well for the web.
This is the content for Writing well for specialists.
<%= render "govuk_publishing_components/components/accordion", {
disable_ga4: true,
items: [
{
heading: {
text: "Writing well for the web"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Writing well for the web.</p>")
}
},
{
heading: {
text: "Writing well for specialists"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Writing well for specialists.</p>")
}
}
]
} %>
Adds custom data attributes to each section of the accordion. Accepts a hash, so multiple attributes can be added.
The data_attributes
option applies attributes to the outermost element in the accordion. Individual items can also have their own data_attributes
hash, which are placed on the button
that triggers the opening and closing of that section - useful for differentiating between each section of the accordion.
This is the content for Writing well for the web.
This is the content for Writing well for specialists.
This is the content for Know your audience.
This is the content for How people read.
<%= render "govuk_publishing_components/components/accordion", {
data_attributes: {
custom_data_attr: "custom-data-attr-accordion"
},
items: [
{
heading: {
text: "Writing well for the web"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Writing well for the web.</p>")
},
data_attributes: {
custom_data_attr: "custom-data-attr-accordion-item-1"
}
},
{
heading: {
text: "Writing well for specialists"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Writing well for specialists.</p>")
},
data_attributes: {
custom_data_attr: "custom-data-attr-accordion-item-2"
}
},
{
heading: {
text: "Know your audience"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Know your audience.</p>")
},
data_attributes: {
custom_data_attr: "custom-data-attr-accordion-item-3"
}
},
{
heading: {
text: "How people read"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for How people read.</p>")
},
data_attributes: {
custom_data_attr: "custom-data-attr-accordion-item-4"
}
}
]
} %>
This will alter the level of the heading, not the appearance of the heading.
This is the content for Writing well for the web.
This is the content for Writing well for specialists.
This is the content for Know your audience.
This is the content for How people read.
<%= render "govuk_publishing_components/components/accordion", {
heading_level: 3,
items: [
{
heading: {
text: "Writing well for the web"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Writing well for the web.</p>")
}
},
{
heading: {
text: "Writing well for specialists"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Writing well for specialists.</p>")
}
},
{
heading: {
text: "Know your audience"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Know your audience.</p>")
}
},
{
heading: {
text: "How people read"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for How people read.</p>")
}
}
]
} %>
The component accepts a number for margin bottom from 0
to 9
(0px
to 60px
) using the GOV.UK Frontend spacing scale. It defaults to having a margin bottom of 30px
.
This is the content for Writing well for the web.
This is the content for Writing well for specialists.
<%= render "govuk_publishing_components/components/accordion", {
margin_bottom: 0,
items: [
{
heading: {
text: "Writing well for the web"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Writing well for the web.</p>")
}
},
{
heading: {
text: "Writing well for specialists"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Writing well for specialists.</p>")
}
}
]
} %>
Adding expanded: true
to the item will mean the section defaults to being open, rather than closed. Once a user opens or closes a section, the state of each section is remembered.
This is the content for Writing well for specialists.
This is the content for Know your audience.
This is the content for How people read.
<%= render "govuk_publishing_components/components/accordion", {
items: [
{
heading: {
text: "Writing well for the web"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Writing well for the web.</p>")
},
expanded: true
},
{
heading: {
text: "Writing well for specialists"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Writing well for specialists.</p>")
}
},
{
heading: {
text: "Know your audience"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for Know your audience.</p>")
}
},
{
heading: {
text: "How people read"
},
content: {
html: sanitize("<p class=\"govuk-body\">This is the content for How people read.</p>")
}
}
]
} %>