Skip to content

Commit 599f1e3

Browse files
committed
Move $heading to AccordionSection
Removes the variables storing the class name. Future refactoring will switch it to be a simple variable in the constructor, rather than a property on the class, but for now it's necessary so it can be accessed from within `Accordion` during refactoring.
1 parent b602819 commit 599f1e3

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

packages/govuk-frontend/src/govuk/components/accordion/accordion-section.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ export class AccordionSection extends Component {
6262
})
6363

6464
this.$toggle = createShowHideToggle(this.$toggleIcon, this.$toggleText)
65+
66+
this.$heading = this.$root.querySelector(
67+
'.govuk-accordion__section-heading'
68+
)
69+
70+
if (!this.$heading) {
71+
throw new ElementError({
72+
component: AccordionSection,
73+
identifier: `Section heading (\`.govuk-accordion__section-heading\`)`
74+
})
75+
}
6576
}
6677
}
6778

packages/govuk-frontend/src/govuk/components/accordion/accordion.mjs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ const sectionExpandedModifier = 'govuk-accordion__section--expanded'
1414
/** @private */
1515
const sectionButtonClass = 'govuk-accordion__section-button'
1616

17-
/** @private */
18-
const sectionHeadingClass = 'govuk-accordion__section-heading'
19-
2017
/** @private */
2118
const iconClass = 'govuk-accordion-nav__chevron'
2219

@@ -179,16 +176,8 @@ export class Accordion extends ConfigurableComponent {
179176
// before it gets moved to the `AccordionSection` class
180177
const $header = section.$header
181178

182-
const $heading = $header.querySelector(`.${sectionHeadingClass}`)
183179
const $summary = $header.querySelector(`.${sectionSummaryClass}`)
184180

185-
if (!$heading) {
186-
throw new ElementError({
187-
component: Accordion,
188-
identifier: `Section heading (\`.${sectionHeadingClass}\`)`
189-
})
190-
}
191-
192181
// Create a button element that will replace the
193182
// '.govuk-accordion__section-button' span
194183
const $button = createElement('button', {
@@ -223,8 +212,8 @@ export class Accordion extends ConfigurableComponent {
223212

224213
$button.appendChild(section.$toggle)
225214

226-
$heading.removeChild(section.$buttonPlaceholder)
227-
$heading.appendChild($button)
215+
section.$heading.removeChild(section.$buttonPlaceholder)
216+
section.$heading.appendChild($button)
228217
}
229218

230219
/**

0 commit comments

Comments
 (0)