-
Notifications
You must be signed in to change notification settings - Fork 335
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
Conditional reveals fail if ID contains characters that have a special meaning in CSS #1808
Comments
One solution to this may be to use CSS.escape, although we'd need to include a polyfill for it: if (!controls || !$module.querySelector('#' + CSS.escape(controls))) { |
There's a potential fix (using Attaching this to the 4.0 milestone so we can flag it as a potential breaking change in the release notes. |
@36degrees I hit this bug today. My hunch was that switching to |
Based on #1843 fixing this, changing the label from 'Days' to 'Hours' as I think we have a solution that works that doesn't involve polyfilling |
When radios and checkboxes with conditional reveals are initialised, we check that the element targeted by
aria-controls
exists:govuk-frontend/src/govuk/components/radios/radios.js
Lines 20 to 26 in 387c33d
If the conditionally revealed element has an ID that contains characters that have a special meaning in CSS, such as
[]
, this fails because the ID needs to be escaped:In some cases, the conditional reveal may fail silently, for example if the generated ID makes a valid CSS selector:
In this case, the evaluated selector would be:
Which is interpreted as element with ID
conditional-rejectionReasons
, also having attributecandidate-actions
, which does not match any element on the page, and so the initialise function returns early.If it was correctly escaped, it should be:
This is especially problematic where we automatically generate IDs based on
name
, as it's more likely that users will use a name that includes[]
.The text was updated successfully, but these errors were encountered: