-
Notifications
You must be signed in to change notification settings - Fork 337
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 ElementError (not found) if checkboxes or radios have no input items #4236
Conversation
📋 StatsFile sizes
Modules
View stats and visualisations on the review app Action run for 48903c5 |
Suspect we also want to throw an error here, for the case where the element with govuk-frontend/packages/govuk-frontend/src/govuk/components/checkboxes/checkboxes.mjs Lines 56 to 60 in df9c59a
|
packages/govuk-frontend/src/govuk/components/checkboxes/checkboxes.mjs
Outdated
Show resolved
Hide resolved
df9c59a
to
6883f26
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.
Am I allowed to approve it yet??
Haha, I'm just looking at the stuff in my comment - which wouldn't be caused by a user-created parameter, except I guess in the case where they're using HTML and make a mistake. |
@colinrotherham Should hopefully be good for review now. |
@@ -51,13 +51,21 @@ export class Checkboxes extends GOVUKFrontendComponent { | |||
|
|||
this.$inputs.forEach(($input) => { | |||
const targetId = $input.getAttribute('data-aria-controls') |
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.
We create item and conditional IDs internally in the template:
govuk-frontend/packages/govuk-frontend/src/govuk/components/checkboxes/template.njk
Line 62 in 704cf6d
{% set conditionalId = "conditional-" + id %} |
However, this check is still useful for folks using HTML instead of the Nunjucks macros, as they'd be inputting their own data-aria-controls
and ids.
packages/govuk-frontend/src/govuk/components/checkboxes/checkboxes.mjs
Outdated
Show resolved
Hide resolved
packages/govuk-frontend/src/govuk/components/checkboxes/checkboxes.mjs
Outdated
Show resolved
Hide resolved
if (!targetElement) { | ||
throw new ElementError(targetElement, { | ||
componentName: 'Checkboxes', | ||
identifier: `.govuk-checkboxes__conditional #${targetId}` |
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 like how this is clearer, but realised we only select by ID?
identifier: `.govuk-checkboxes__conditional #${targetId}` | |
identifier: `#${targetId}` |
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 do prefer CSS selectors though, see https://github.com/alphagov/govuk-frontend/pull/4236/files#r1331775855
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 happy to revert this for this PR, but something to discuss when we review the content - is targetId
user-friendly enough when there may be some kind of issue with it? Ideally having the parent radios item info in there would be great, but realise I may be going too far.
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.
Did some digging, and we used to scope it to $module
before 266f877
I suppose since then the target could genuinely be anywhere on the page?
E.g. Tick a box in a left column and a question is revealed on the right?
packages/govuk-frontend/src/govuk/components/checkboxes/checkboxes.mjs
Outdated
Show resolved
Hide resolved
We handle these IDs internally, but in the case where somebody is coding using HTML instead of the Nunjucks macros, they still might get caught out.
cdccefc
to
48903c5
Compare
Closes #4131