Skip to content
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

Merged
merged 7 commits into from
Oct 23, 2023
Merged

Conversation

domoscargin
Copy link
Contributor

Closes #4126

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4266 September 27, 2023 15:11 Inactive
@github-actions
Copy link

github-actions bot commented Sep 27, 2023

📋 Stats

File sizes

File Size
dist/govuk-frontend-4.7.0.min.css 120.66 KiB
dist/govuk-frontend-4.7.0.min.js 51.56 KiB
dist/govuk-frontend-ie8-4.7.0.min.css 81.59 KiB
packages/govuk-frontend/dist/govuk/all.bundle.js 76.38 KiB
packages/govuk-frontend/dist/govuk/all.bundle.mjs 71.71 KiB
packages/govuk-frontend/dist/govuk/all.mjs 3.8 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs 359 B
packages/govuk-frontend/dist/govuk/govuk-frontend.min.css 113.99 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend.min.js 37.66 KiB
packages/govuk-frontend/dist/govuk/i18n.mjs 5.3 KiB

Modules

File Size
all.mjs 68.04 KiB
components/accordion/accordion.mjs 20.92 KiB
components/button/button.mjs 4.16 KiB
components/character-count/character-count.mjs 20.41 KiB
components/checkboxes/checkboxes.mjs 5.3 KiB
components/error-summary/error-summary.mjs 5.46 KiB
components/exit-this-page/exit-this-page.mjs 15.47 KiB
components/header/header.mjs 3.3 KiB
components/notification-banner/notification-banner.mjs 4 KiB
components/radios/radios.mjs 4.3 KiB
components/skip-link/skip-link.mjs 3.29 KiB
components/tabs/tabs.mjs 9.05 KiB

View stats and visualisations on the review app


Action run for c632049

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4266 September 28, 2023 23:13 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4266 October 2, 2023 06:54 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4266 October 2, 2023 06:55 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4266 October 3, 2023 12:40 Inactive
@domoscargin domoscargin marked this pull request as ready for review October 3, 2023 12:57

describe('errors at instantiation', () => {
let examples
describe('errors at instantiation', () => {
Copy link
Contributor Author

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]`)'
Copy link
Contributor Author

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}\`)`
Copy link
Contributor Author

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).

Copy link
Contributor

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?

  1. Accordion: Module ([data-module=govuk-accordion])
  2. Accordion: Section (.govuk-accordion__section)
  3. Accordion: Section header (.govuk-accordion__section-header)
  4. Accordion: Section heading (.govuk-accordion__section-heading)
  5. Accordion: Section button (.govuk-accordion__section-button)
  6. etc

The word "Section" then doesn't have to mean <section> element

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4266 October 13, 2023 13:47 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4266 October 13, 2023 16:54 Inactive
@colinrotherham colinrotherham changed the base branch from main to puppeteer-arguments October 16, 2023 08:14
Base automatically changed from puppeteer-arguments to main October 17, 2023 14:37
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4266 October 19, 2023 16:36 Inactive
@domoscargin
Copy link
Contributor Author

Rebased - allows this PR to be simplified, since all the beforeInitialisation wrangling has already been merged.

@@ -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) {
Copy link
Contributor Author

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'
Copy link
Contributor Author

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.

Copy link
Member

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).

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4266 October 19, 2023 17:17 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4266 October 19, 2023 17:20 Inactive
Copy link
Member

@romaricpascal romaricpascal left a 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}">\`)`
Copy link
Member

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.

Suggested change
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}">\`)`
Copy link
Member

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:

Suggested change
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:

Suggested change
identifier: `Section button (\`<span class="${this.sectionButtonClass}">\`)`
identifier: `Section button placeholder (\`<span class="${this.sectionButtonClass}">\`)`

Copy link
Contributor

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?

Copy link
Member

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 😊

Copy link
Contributor Author

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.

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4266 October 20, 2023 16:24 Inactive
@colinrotherham
Copy link
Contributor

@domoscargin I've rebased this PR with #4329 and #4345

We've renamed renderAndInitialise() to render() as not all components have JavaScript (to initialise)

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4266 October 23, 2023 10:15 Inactive
@domoscargin domoscargin merged commit 4714006 into main Oct 23, 2023
43 checks passed
@domoscargin domoscargin deleted the bk-accordion-errors branch October 23, 2023 10:53
@romaricpascal romaricpascal mentioned this pull request Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Throw errors during Accordion initialisation if key HTML elements are missing
4 participants