@@ -20,9 +20,6 @@ const iconClass = 'govuk-accordion-nav__chevron'
2020/** @private */
2121const iconOpenModifier = 'govuk-accordion-nav__chevron--down'
2222
23- /** @private */
24- const sectionSummaryClass = 'govuk-accordion__section-summary'
25-
2623/**
2724 * Accordion component
2825 *
@@ -172,12 +169,6 @@ export class Accordion extends ConfigurableComponent {
172169 * @param {number } index - Section index
173170 */
174171 constructHeaderMarkup ( section , index ) {
175- // TEMPORARY: This helps keeping current code intact
176- // before it gets moved to the `AccordionSection` class
177- const $header = section . $header
178-
179- const $summary = $header . querySelector ( `.${ sectionSummaryClass } ` )
180-
181172 // Create a button element that will replace the
182173 // '.govuk-accordion__section-button' span
183174 const $button = createElement ( 'button' , {
@@ -202,11 +193,8 @@ export class Accordion extends ConfigurableComponent {
202193 $button . appendChild ( this . getButtonPunctuationEl ( ) )
203194
204195 // If summary content exists add to DOM in correct order
205- if ( $summary ) {
206- // Replace the original summary `div` with the new summary `span`
207- $summary . remove ( )
208-
209- $button . appendChild ( this . createSummarySpan ( $summary ) )
196+ if ( section . $summary ) {
197+ $button . appendChild ( section . $summary )
210198 $button . appendChild ( this . getButtonPunctuationEl ( ) )
211199 }
212200
@@ -216,37 +204,6 @@ export class Accordion extends ConfigurableComponent {
216204 section . $heading . appendChild ( $button )
217205 }
218206
219- /**
220- * Creates the `<span>` element with the summary for the section
221- *
222- * This is necessary because the summary line text is now inside
223- * a button element, which can only contain phrasing content, and
224- * not a `<div>` element
225- *
226- * @param {Element } $summary - The original `<div>` containing the summary
227- * @returns {HTMLSpanElement } - The `<span>` element containing the summary
228- */
229- createSummarySpan ( $summary ) {
230- // Create an inner summary container to limit the width of the summary
231- // focus state
232- const $summarySpanFocus = createElement (
233- 'span' ,
234- {
235- class : 'govuk-accordion__section-summary-focus'
236- } ,
237- Array . from ( $summary . childNodes )
238- )
239-
240- const $summarySpan = createElement ( 'span' , { } , [ $summarySpanFocus ] )
241-
242- // Get original attributes, and pass them to the replacement
243- for ( const attr of Array . from ( $summary . attributes ) ) {
244- $summarySpan . setAttribute ( attr . name , attr . value )
245- }
246-
247- return $summarySpan
248- }
249-
250207 /**
251208 * When a section is opened by the user agent via the 'beforematch' event
252209 *
@@ -335,9 +292,8 @@ export class Accordion extends ConfigurableComponent {
335292
336293 ariaLabelParts . push ( `${ section . $headingText . textContent } ` . trim ( ) )
337294
338- const $summary = $section . querySelector ( `.${ sectionSummaryClass } ` )
339- if ( $summary ) {
340- ariaLabelParts . push ( `${ $summary . textContent } ` . trim ( ) )
295+ if ( section . $summary ) {
296+ ariaLabelParts . push ( `${ section . $summary . textContent } ` . trim ( ) )
341297 }
342298
343299 const ariaLabelMessage = expanded
0 commit comments