-
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
Add Checkboxes and Radios conditional reveal #616
Conversation
This is blocked on modules, since polyfills overlap components and we'll have a massive amount of duplication between components. See #619 |
29aa807
to
1964600
Compare
461d8b0
to
335704f
Compare
335704f
to
5a13bbd
Compare
5a13bbd
to
4ab7a08
Compare
4ab7a08
to
3035af8
Compare
3035af8
to
d1b6a4c
Compare
d1b6a4c
to
6581d52
Compare
6581d52
to
02f98c6
Compare
02f98c6
to
3815bd6
Compare
3815bd6
to
3e5390e
Compare
3e5390e
to
6f23c7c
Compare
@@ -20,6 +30,11 @@ | |||
for: id | |||
}) | indent(4) | trim }} | |||
</div> | |||
{% if item.conditional %} | |||
<div class="govuk-checkboxes__conditional" id="{{ conditionalId }}"> | |||
{{ item.conditional.html | safe }} |
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.
This feels like a big security risk considering we expect people to put html in here that contains form inputs which often replay user input...
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.
see #514
src/radios/radios.test.js
Outdated
expect(isVisible).toBeTruthy() | ||
}) | ||
}) | ||
describe('must be hidden if JavaScript is avaliable and is collapsed', () => { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
src/checkboxes/_checkboxes.scss
Outdated
border-left: $conditional-border-width solid $govuk-border-colour; | ||
|
||
// If JavaScript fails, make sure conditional content is not hidden. | ||
.js-enabled &[aria-hidden="true"] { |
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.
Investigate if we can do this without a global class
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.
Reviewed offline yesterday. Required changes were made. Did a second round of tests today.
👍 Great work in here. We should try to align the other scripts to this approach.
Don't forget to update the changelog and rebase/mark the fix commits to squash them.
@alex-ju just need to clean the tests up, and then this'll be ready to go. |
TODO: |
src/checkboxes/checkboxes.test.js
Outdated
}) | ||
|
||
describe('Checkboxes', () => { | ||
describe('must be visible as static content if JavaScript is unavaliable or fails', () => { |
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.
It'd be good to nail these describe and it blocks – it's unclear to me reading this what we're trying to test and what is context.
For example 'with no aria attributes' and 'with visible content' as currently written could easily be interpreted as context ('when the thing does not have aria attributes', 'when the thing has visible content').
I'd suggest this would be better as something like:
Describe checkboxes with conditional reveals
Describe when Javascript is unavailable or fails
It does not have any ARIA attributes
It makes the conditional content visible
The benefit of this structure is that the nesting still 'works', but each line also stands on its own – describe
blocks read as context and it
blocks read as assertions.
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.
Also, typo on unavaliable (appears a few times)
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 like I said above, I'm cleaning these up after the review with alex and jani
src/checkboxes/checkboxes.test.js
Outdated
const $ = await goToAndGetComponent('checkboxes', 'with-conditional') | ||
const $component = $('.govuk-checkboxes') | ||
|
||
const hasAriaHidden = $component.find('[aria-hidden]').length |
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.
The checkbox itself would never have aria-hidden
right? That attribute would be on the conditional content? Should this be a separate test?
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.
.find
will look for any child element with aria-hidden so this should catch any issues.
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.
Makes sense, though not sure that's clear. Can we be more specific and check the elements that we put the aria attributes on?
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.
Sorted
4051b11
to
01fd602
Compare
fd07ef4
to
d82790b
Compare
d82790b
to
0a0ce3c
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.
Went through the code again. Looks good to be merged to me.
This pull requests adds the conditional reveal functionality for radios and checkboxes.
It replicates the behaviour in GOV.UK Elements, see known issues below for possible improvements at a later date.
I took the initial code in elements, rewrote the tests, made sure they were passing against the old code. Then refactored into modules as seen in this pull request.
It also includes:
Manual tests
Browsers
IE8
IE9+
Safari
Chrome
Firefox 58 with custom colours
AT testing
Checkboxes: Email, unchecked, checkbox > Email checked > Email address, edit text
Radios: Email, collapsed, radio button, 1 of 3. > Email, selected expanded, radio button, 1 of 3 > Email address, edit text
Checkboxes: Email checkbox, not checked > Checked collapsed; Checked expanded > Email address. How do you want to be contacted? Email address edit. Type in text.
Radios: Email radio button, checked. Email address. How do you want to be contacted? Email address edit. Type in text.
Note: on checkboxes, the initial state is being announced before the final state (i.e. Checked collapsed; Checked expanded); however this behaviour is consistent with Elements so we'll try to address this as a separate PR.
Checkboxes: Email checkbox collapsed not checked/Checked expanded > Email address edit.
Radios: Email radio button expanded 1 of 3 > Email address edit.
TODO:
Known issues
Radios are not announcing as expected, this is an issue seen in GOV.UK Elements too: alphagov/govuk_elements#575
Review links:
https://trello.com/c/R5WwqbpH/803-5-add-conditional-reveal-script-to-radios-and-checkboxes