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

Add Checkboxes and Radios conditional reveal #616

Merged
merged 7 commits into from
Apr 25, 2018
Merged

Conversation

NickColley
Copy link
Contributor

@NickColley NickColley commented Mar 22, 2018

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:

  • Macro interface
  • New polyfills

Manual tests

Browsers

  • IE8+
  • Latest Safari, Chrome, Firefox, Edge
IE8 ie8-checkboxes ie8-radios
IE9+ ie9-checkboxes ie9-radios
Safari safari-checkboxes safari-radios
Chrome chrome-checkboxes chrome-radios
Firefox 58 with custom colours screen shot 2018-04-19 at 14 27 57 screen shot 2018-04-19 at 14 28 13

AT testing

  • Custom colours
  • VoiceOver on Safari
    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
  • JAWS17/18 on IE11
    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.
  • NDVA on Firefox52/IE11
    Checkboxes: Email checkbox collapsed not checked/Checked expanded > Email address edit.
    Radios: Email radio button expanded 1 of 3 > Email address edit.
  • Dragon Naturally Speaking on Firefox52/IE11

TODO:

  • Complete cross browser testing
  • Complete assistive technology testing
  • Add template tests
  • Add accessibility acceptance criteria for radios

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

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 March 22, 2018 13:58 Inactive
@NickColley NickColley changed the title WIP: Add checkbox conditional reveal WIP: Add conditional reveal Mar 22, 2018
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 March 22, 2018 14:48 Inactive
@NickColley
Copy link
Contributor Author

This is blocked on modules, since polyfills overlap components and we'll have a massive amount of duplication between components. See #619

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 17, 2018 14:26 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 17, 2018 15:39 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 17, 2018 15:51 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 17, 2018 15:58 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 17, 2018 16:15 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 17, 2018 16:17 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 17, 2018 16:20 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 17, 2018 16:35 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 17, 2018 16:37 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 17, 2018 16:51 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 17, 2018 16:57 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 19, 2018 09:57 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 19, 2018 10:04 Inactive
@@ -20,6 +30,11 @@
for: id
}) | indent(4) | trim }}
</div>
{% if item.conditional %}
<div class="govuk-checkboxes__conditional" id="{{ conditionalId }}">
{{ item.conditional.html | safe }}
Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #514

expect(isVisible).toBeTruthy()
})
})
describe('must be hidden if JavaScript is avaliable and is collapsed', () => {

This comment was marked as resolved.

border-left: $conditional-border-width solid $govuk-border-colour;

// If JavaScript fails, make sure conditional content is not hidden.
.js-enabled &[aria-hidden="true"] {
Copy link
Contributor Author

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

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 23, 2018 16:40 Inactive
alex-ju
alex-ju previously approved these changes Apr 24, 2018
Copy link
Contributor

@alex-ju alex-ju left a 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.

@NickColley
Copy link
Contributor Author

@alex-ju just need to clean the tests up, and then this'll be ready to go.

@kr8n3r
Copy link

kr8n3r commented Apr 24, 2018

TODO:
changelog

})

describe('Checkboxes', () => {
describe('must be visible as static content if JavaScript is unavaliable or fails', () => {
Copy link
Contributor

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.

Copy link
Contributor

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)

Copy link
Contributor Author

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

const $ = await goToAndGetComponent('checkboxes', 'with-conditional')
const $component = $('.govuk-checkboxes')

const hasAriaHidden = $component.find('[aria-hidden]').length
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorted

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 24, 2018 15:43 Inactive
@NickColley NickColley changed the title Add conditional reveal Add Checkboxes and Radios conditional reveal Apr 24, 2018
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 24, 2018 15:48 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-616 April 24, 2018 15:59 Inactive
Copy link
Contributor

@alex-ju alex-ju left a 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.

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.

5 participants