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

Update legend/label/heading examples to have unique names and ids #2441

Merged
merged 4 commits into from
Dec 6, 2021

Conversation

vanitabarrett
Copy link
Contributor

@vanitabarrett vanitabarrett commented Nov 24, 2021

I came across this when using these examples to test #2083

The current examples for legends, labels and headings have the same name and id (or idPrefix). This meant for things using checkboxes and radios (for example), the checkboxes were appearing as one list of checkboxes for screenreader users, e.g: tickbox 2 of 60.

It also meant that hints were being read incorrectly for some questions, because all hints on the page had the same id (e.g: example-hint).

This commit gives each question a unique name, and either removes the idPrefix so it falls back to the name or gives each question a unique id too.

Each individual commit contains more details on the issues this was causing when testing with assistive technologies and the change that's been made to fix it.

https://govuk-frontend-pr-2441.herokuapp.com/examples/labels-legends-and-headings

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2441 November 24, 2021 14:43 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2441 November 24, 2021 14:58 Inactive
@vanitabarrett vanitabarrett marked this pull request as ready for review November 24, 2021 16:41
@vanitabarrett vanitabarrett requested a review from a team November 24, 2021 16:41
@vanitabarrett vanitabarrett force-pushed the update-label-legends-headings-examples branch from f5da9b1 to 10105ba Compare November 25, 2021 09:57
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2441 November 25, 2021 09:58 Inactive
@vanitabarrett vanitabarrett force-pushed the update-label-legends-headings-examples branch from 10105ba to f8f81c9 Compare November 25, 2021 10:21
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2441 November 25, 2021 10:21 Inactive
@lfdebrux
Copy link
Member

For some reason the radio buttons are now pre-selected on no 🤔

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2441 December 3, 2021 13:30 Inactive
@vanitabarrett
Copy link
Contributor Author

@lfdebrux Really good spot! I've addressed this in 714bece

Vanita Barrett added 4 commits December 3, 2021 15:12
Every example in the legend/label/heading examples has the same `name`
and `idPrefix`. Having the same `name` on every example meant that the
checkboxes and radio buttons looked like they were part of one question.
For example, when testing with Voiceover and Safari, you would hear something
like:

"Yes, radio button, 1 of 60" for a simple yes/no question.

The `idPrefix` is used to prefix the id's for the hints. If not present, the `name`
is used instead. Because the `idPrefix` values were also identical, this led to hints being
associated and read out for the wrong questions because there were multiple hints with
the same `id`.

This commit updates each `name` to give it a unique value. It also removes
the `idPrefix`, which means the `id` will be generated from the `name`. This is ok
in this case as the names are now all unique.
with the existing implementation, each text input in error had
the same id. When testing with NVDA 2021.2 + Firefox, this meant that
when a user tabbed to the text input, they would hear every single label
with `for="input-with-error-message"`, e.g:

```
<h1> govuk-label--xl <h1> govuk-label--l <h1> govuk-label--m <h1> govuk-label--s <h1> No class <label> govuk-label--xl <label> govuk-label--l <label> govuk-label--m <label> govuk-label--s <label> No class  edit  has auto complete
```

This commit replaces the duplicate id's with unique ones to stop this happening
The `id` for text input examples were being set to a blank string.
This was leading to text inputs having an `id` (and therefore an `aria-describedby`)
starting with a dash, i.e: `id="-hint"`. Each text input also had the same `id`.

This commit replaces the blank `id` and uses the same value as the `name` so each
text input has a unique `id`.
The radio button examples had the 'No' radio pre-selected, but we don't
recommend pre-selecting in our guidance and none of the other examples
on this page have any preselected/pre-populated inputs.

The `checked` attribute was already present in the code, but wasn't working
properly because of the duplicate names/ids. Now that we fixed that, it had
the unintentional effect of making the `checked` code work.

This commit removes the `checked` attribute from the radio button examples.
@vanitabarrett vanitabarrett force-pushed the update-label-legends-headings-examples branch from 714bece to 8c3ede7 Compare December 3, 2021 15:21
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2441 December 3, 2021 15:22 Inactive
Copy link
Member

@lfdebrux lfdebrux left a comment

Choose a reason for hiding this comment

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

W3C validator reports no errors or warnings 🙌

@vanitabarrett vanitabarrett merged commit aa5a345 into main Dec 6, 2021
@vanitabarrett vanitabarrett deleted the update-label-legends-headings-examples branch December 6, 2021 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants