-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw errors during accordion initialisation #4266
Conversation
📋 StatsFile sizes
Modules
View stats and visualisations on the review app Action run for c632049 |
77531f9
to
9fc9607
Compare
9fc9607
to
7a8d3c2
Compare
packages/govuk-frontend/src/govuk/components/accordion/accordion.mjs
Outdated
Show resolved
Hide resolved
packages/govuk-frontend/src/govuk/components/accordion/accordion.mjs
Outdated
Show resolved
Hide resolved
packages/govuk-frontend/src/govuk/components/accordion/accordion.mjs
Outdated
Show resolved
Hide resolved
|
||
describe('errors at instantiation', () => { | ||
let examples | ||
describe('errors at instantiation', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed we accidentally had our errors at instantiation
wrapped within the localisation
block.
@@ -122,7 +122,7 @@ export class Accordion extends GOVUKFrontendComponent { | |||
if (!($module instanceof HTMLElement)) { | |||
throw new ElementError($module, { | |||
componentName: 'Accordion', | |||
identifier: '$module' | |||
identifier: 'Root element (`[data-module=govuk-accordion]`)' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to get all the identifiers looking as described in #4299
@@ -140,7 +140,7 @@ export class Accordion extends GOVUKFrontendComponent { | |||
if (!$sections.length) { | |||
throw new ElementError(null, { | |||
componentName: 'Accordion', | |||
identifier: `.${this.sectionClass}` | |||
identifier: `Element (\`.${this.sectionClass}\`)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrinkle here:
I've just gone with using Element
any time the element in question is a div
, but do we want to be specific? Or add a less generic qualifier?
For example, here would we prefer something like Section element
? (Though not that, because <section>
is a thing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to drop "element" and just use the plain English name?
- Accordion: Module (
[data-module=govuk-accordion]
) - Accordion: Section (
.govuk-accordion__section
) - Accordion: Section header (
.govuk-accordion__section-header
) - Accordion: Section heading (
.govuk-accordion__section-heading
) - Accordion: Section button (
.govuk-accordion__section-button
) - etc
The word "Section" then doesn't have to mean <section>
element
17a0798
to
7bb2dc7
Compare
7bb2dc7
to
4141439
Compare
4141439
to
53a2a6a
Compare
Rebased - allows this PR to be simplified, since all the |
@@ -411,7 +411,22 @@ export class Accordion extends GOVUKFrontendComponent { | |||
const $button = $section.querySelector(`.${this.sectionButtonClass}`) | |||
const $content = $section.querySelector(`.${this.sectionContentClass}`) | |||
|
|||
if (!$showHideIcon || !$showHideText || !$button || !$content) { | |||
if (!$button) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note this is our second check for $button
, so I haven't written another test for it. I guess technically you could trigger this slightly differently from the other instance, but the end result is an error. This will be neater if we figure out some kind of caching solution.
).rejects.toEqual({ | ||
name: 'ElementError', | ||
message: | ||
'Accordion: Sections (`.govuk-accordion__section`) not found' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm tempted to suggest we have a new kind of message in ElementError
of this sort:
No sections (<IDENTIFIER>) were found
For when a group of things is empty.
But I wouldn't consider this blocking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it does sound better, indeed, when multiple things are missing. Agreed this wouldn't block the PR and can be dealt with separately (wouldn't even block the pre-release, as the content is not part of the public API).
packages/govuk-frontend/src/govuk/components/accordion/accordion.mjs
Outdated
Show resolved
Hide resolved
bbefc16
to
df1a8cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spotted two little updates we could make to avoid "button" issues mentioning a <span>
element, but happy for them to happen later on 😊
if (!$span) { | ||
throw new ElementError({ | ||
componentName: 'Accordion', | ||
identifier: `Section button (\`<span class="${this.sectionButtonClass}">\`)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick Maybe a little pedantic, but it looked weird to have "button" followed by a span
tag.
identifier: `Section button (\`<span class="${this.sectionButtonClass}">\`)` | |
identifier: `Section button placeholder (\`<span class="${this.sectionButtonClass}">\`)` |
if (!$button) { | ||
throw new ElementError({ | ||
componentName: 'Accordion', | ||
identifier: `Section button (\`<span class="${this.sectionButtonClass}">\`)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick Technically at that stage, it's an actual button
tag, so we could either:
identifier: `Section button (\`<span class="${this.sectionButtonClass}">\`)` | |
identifier: `Section button (\`<button class="${this.sectionButtonClass}">\`)` |
Which would help people look for a button, though what they likely need to do for fixing is making sure the placeholder is in so we turn it into a button with:
identifier: `Section button (\`<span class="${this.sectionButtonClass}">\`)` | |
identifier: `Section button placeholder (\`<span class="${this.sectionButtonClass}">\`)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spotting this
It's a quirk of Accordion that's caught me out too, that this.sectionButtonClass
matches different things
Should we instead return early for !$button
here, knowing we've thrown already for the placeholder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! At this stage, we're the ones that created the <button>
so we can early return like in other listener for now 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look, folks. I've now made these tweaks in the latest commit.
df1a8cb
to
9b811a5
Compare
@domoscargin I've rebased this PR with #4329 and #4345 We've renamed |
Closes #4126