Skip to content

Commit

Permalink
Return early for elements we've created
Browse files Browse the repository at this point in the history
  • Loading branch information
domoscargin committed Oct 3, 2023
1 parent 7f0f4b1 commit 7a8d3c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,13 @@ export class Accordion extends GOVUKFrontendComponent {
const $button = $section.querySelector(`.${this.sectionButtonClass}`)
const $content = $section.querySelector(`.${this.sectionContentClass}`)

if (!$showHideIcon || !$showHideText || !$button || !$content) {
// Return early for elements created during set up
if (!$showHideIcon || !$showHideText) {
return
}

if (!$button || !$content) {
const [check] = /** @type {const} */ ([
[$showHideIcon, this.upChevronIconClass],
[$showHideText, this.sectionShowHideTextClass],
[$button, this.sectionButtonClass],
[$content, this.sectionContentClass]
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,6 @@ describe('/components/accordion', () => {
})

const toggleButtonElements = [
'.govuk-accordion-nav__chevron',
'.govuk-accordion__section-toggle-text',
'.govuk-accordion__section-button',
'.govuk-accordion__section-content'
]
Expand Down

0 comments on commit 7a8d3c2

Please sign in to comment.