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.

Preserve

Hierarchy

  • GOVUKFrontendComponent
    • Accordion

Constructors

Properties

$module: HTMLElement
$sections: NodeListOf<Element>
$showAllButton: HTMLButtonElement = null
$showAllIcon: HTMLElement = null
$showAllText: HTMLElement = null
browserSupportsSessionStorage: boolean = false
controlsClass: string = 'govuk-accordion__controls'
downChevronIconClass: string = 'govuk-accordion-nav__chevron--down'
i18n: I18n
sectionButtonClass: string = 'govuk-accordion__section-button'
sectionClass: string = 'govuk-accordion__section'
sectionContentClass: string = 'govuk-accordion__section-content'
sectionExpandedClass: string = 'govuk-accordion__section--expanded'
sectionHeaderClass: string = 'govuk-accordion__section-header'
sectionHeadingClass: string = 'govuk-accordion__section-heading'
sectionHeadingDividerClass: string = 'govuk-accordion__section-heading-divider'
sectionHeadingTextClass: string = 'govuk-accordion__section-heading-text'
sectionHeadingTextFocusClass: string = 'govuk-accordion__section-heading-text-focus'
sectionShowHideTextClass: string = 'govuk-accordion__section-toggle-text'
sectionShowHideToggleClass: string = 'govuk-accordion__section-toggle'
sectionShowHideToggleFocusClass: string = 'govuk-accordion__section-toggle-focus'
sectionSummaryClass: string = 'govuk-accordion__section-summary'
sectionSummaryFocusClass: string = 'govuk-accordion__section-summary-focus'
showAllClass: string = 'govuk-accordion__show-all'
showAllTextClass: string = 'govuk-accordion__show-all-text'
upChevronIconClass: string = 'govuk-accordion-nav__chevron'
defaults: AccordionConfig = ...

Accordion default config

See

AccordionConfig

Constant

moduleName: string = 'govuk-accordion'

Name for the component used when initialising using data-module attributes.

Methods

  • Private

    Set section attributes when opened/closed

    Parameters

    • expanded: boolean

      Section expanded

    • $section: Element

      Section element

    Returns void

Generated using TypeDoc