HTML element to use for accordion
Optional
config: AccordionConfig = {}Accordion config
Protected
_$rootPrivate
$sectionsPrivate
$showPrivate
$showPrivate
$showPrivate
controlsPrivate
downPrivate
i18nPrivate
sectionPrivate
sectionPrivate
sectionPrivate
sectionPrivate
sectionPrivate
sectionPrivate
sectionPrivate
sectionPrivate
sectionPrivate
sectionPrivate
sectionPrivate
sectionPrivate
sectionPrivate
sectionPrivate
showPrivate
showPrivate
upStatic
Constant
defaultsAccordion default config
Static
elementStatic
moduleName for the component used when initialising using data-module attributes.
Static
Constant
schemaAccordion config schema
Protected
$rootProtected
Returns the root element of the component
Protected
configProtected
Returns the root element of the component
Internal
Virtual
configOverride
Function which defines configuration overrides to prioritize properties from the root element's dataset.
It should take a subset of configuration as input and return a new configuration object with properties that should be overridden based on the root element's dataset. A Symbol is used for indexing to prevent conflicts.
Optional
param: Partial<AccordionConfig>Configuration object
return - Configuration object
Private
arePrivate
Check if all sections are open
True if all sections are open
Private
constructPrivate
Construct section header
Section header
Section index
Private
getPrivate
Create an element to improve semantics of the section button with punctuation
Adding punctuation to the button can also improve its general semantics by dividing its contents into thematic chunks. See https://github.com/alphagov/govuk-frontend/issues/2327#issuecomment-922957442
DOM element
Get the identifier for a section
We need a unique way of identifying each content in the Accordion.
Since an #id
should be unique and an id
is required for aria-
attributes id
can be safely used.
Section element
Identifier for section
Private
initPrivate
Initialise controls and set attributes
Private
initPrivate
Initialise section headers
Private
isPrivate
Get state of section
Section element
True if expanded
Private
onPrivate
When a section is opened by the user agent via the 'beforematch' event
Generic event
Private
onPrivate
When section toggled, set and store state
Section element
Private
onPrivate
When Open/Close All toggled, set and store state
Private
setPrivate
Set section attributes when opened/closed
Section expanded
Section element
Private
setPrivate
Read the state of the accordions from sessionStorage
Section element
Private
storePrivate
Set the state of the accordions in sessionStorage
Section element
Whether the section is expanded
Private
updatePrivate
Update "Show all sections" button
Section expanded
Static
check
Accordion component
This allows a collection of sections to be collapsed by default, showing only their headers. Sections can be expanded or collapsed individually by clicking their headers. A "Show all sections" button is also added to the top of the accordion, which switches to "Hide all sections" when all the sections are expanded.
The state of each section is saved to the DOM via the
aria-expanded
attribute, which also provides accessibility.