@@ -182,7 +182,6 @@ export class Accordion extends ConfigurableComponent {
182182 // before it gets moved to the `AccordionSection` class
183183 const $header = section . $header
184184
185- const $span = $header . querySelector ( `.${ sectionButtonClass } ` )
186185 const $heading = $header . querySelector ( `.${ sectionHeadingClass } ` )
187186 const $summary = $header . querySelector ( `.${ sectionSummaryClass } ` )
188187
@@ -193,13 +192,6 @@ export class Accordion extends ConfigurableComponent {
193192 } )
194193 }
195194
196- if ( ! $span ) {
197- throw new ElementError ( {
198- component : Accordion ,
199- identifier : `Section button placeholder (\`<span class="${ sectionButtonClass } ">\`)`
200- } )
201- }
202-
203195 // Create a button element that will replace the
204196 // '.govuk-accordion__section-button' span
205197 const $button = createElement ( 'button' , {
@@ -209,7 +201,7 @@ export class Accordion extends ConfigurableComponent {
209201
210202 // Copy all attributes from $span to $button (except `id`, which gets added
211203 // to the `$headingText` element)
212- for ( const attr of Array . from ( $span . attributes ) ) {
204+ for ( const attr of Array . from ( section . $buttonPlaceholder . attributes ) ) {
213205 if ( attr . name !== 'id' ) {
214206 $button . setAttribute ( attr . name , attr . value )
215207 }
@@ -220,7 +212,7 @@ export class Accordion extends ConfigurableComponent {
220212 // 2. Punctuation
221213 // 3. (Optional: Summary line followed by punctuation)
222214 // 4. Show / hide toggle
223- $button . appendChild ( this . createHeadingText ( $span ) )
215+ $button . appendChild ( this . createHeadingText ( section . $buttonPlaceholder ) )
224216 $button . appendChild ( this . getButtonPunctuationEl ( ) )
225217
226218 // If summary content exists add to DOM in correct order
@@ -234,17 +226,17 @@ export class Accordion extends ConfigurableComponent {
234226
235227 $button . appendChild ( section . $toggle )
236228
237- $heading . removeChild ( $span )
229+ $heading . removeChild ( section . $buttonPlaceholder )
238230 $heading . appendChild ( $button )
239231 }
240232
241233 /**
242234 * Creates the `<span>` containing the text of the section's heading
243235 *
244- * @param {Element } $span - The heading of the span
236+ * @param {Element } $buttonPlaceholder - The heading of the span
245237 * @returns {HTMLSpanElement } - The `<span>` containing the text of the section's heading
246238 */
247- createHeadingText ( $span ) {
239+ createHeadingText ( $buttonPlaceholder ) {
248240 // Create an inner heading text container to limit the width of the focus
249241 // state
250242 const $headingTextFocus = createElement (
@@ -254,15 +246,15 @@ export class Accordion extends ConfigurableComponent {
254246 } ,
255247 // span could contain HTML elements which need moving to the new span
256248 // (see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content)
257- Array . from ( $span . childNodes )
249+ Array . from ( $buttonPlaceholder . childNodes )
258250 )
259251
260252 // Create container for heading text so it can be styled
261253 const $headingText = createElement (
262254 'span' ,
263255 {
264256 class : sectionHeadingTextClass ,
265- id : $span . id
257+ id : $buttonPlaceholder . id
266258 } ,
267259 [ $headingTextFocus ]
268260 )
0 commit comments