Module: CCS::FrontendHelpers::GovUKFrontend::Accordion

Included in:
CCS::FrontendHelpers::GovUKFrontend
Defined in:
lib/ccs/frontend_helpers/govuk_frontend/accordion.rb

Overview

GOV.UK Accordion

This helper is used for generating the accordion component from the GDS - Components - Accordion

Instance Method Summary collapse

Instance Method Details

#govuk_accordion(accordion_id, accordion_sections, **options) ⇒ ActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Accordion component

Parameters:

  • accordion_id (String)

    used as an id in the HTML for the accordion as a whole, and also as a prefix for the ids of the section contents and the buttons that open them

  • accordion_sections (Array<Hash>)

    an array of accordion section attributes. See Section#initialize for details of the items in the array.

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the accordion HTML

  • :heading_level (Integer) — default: 2

    heading level, from 1 to 6

  • :hide_all_sections_text (String)

    The text content of the ‘Hide all sections’ button at the top of the accordion when all sections are expanded

  • :hide_section_text (String)

    The text content of the ‘Hide’ button within each section of the accordion, which is visible when the section is expanded

  • :hide_section_aria_label_text (String)

    Text made available to assistive technologies, like screen-readers, as the final part of the toggle’s accessible name when the section is expanded. Defaults to “Hide this section”.

  • :show_all_sections_text (String)

    The text content of the ‘Show all sections’ button at the top of the accordion when at least one section is collapsed

  • :show_section_text (String)

    The text content of the ‘Show’ button within each section of the accordion, which is visible when the section is collapsed

  • :show_section_aria_label_text (String)

    Text made available to assistive technologies, like screen-readers, as the final part of the toggle’s accessible name when the section is collapsed. Defaults to “Show this section”.

  • :attributes (Hash)

    any additional attributes that will added as part of the HTML

Returns:

  • (ActiveSupport::SafeBuffer)


22
23
24
# File 'lib/ccs/frontend_helpers/govuk_frontend/accordion.rb', line 22

def govuk_accordion(accordion_id, accordion_sections, **options)
  Components::GovUK::Accordion.new(context: self, accordion_id: accordion_id, accordion_sections: accordion_sections, **options).render
end