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

Announce whitespace in screen reader announcements of visually hidden text #3836

Merged
merged 2 commits into from
Jun 28, 2023

Conversation

hannalaakso
Copy link
Member

@hannalaakso hannalaakso commented Jun 20, 2023

This PR fixes a bug in the visually hidden helper class where any whitespace surrounding visually hidden text isn't announced by screen readers.

The issue

The issue came up in user research, with a user saying that it was challenging to understand the JAWS announcement of the <h1> on the GOV.UK search results page. The issue has also previously been reported to JAWS. I can replicate it in in JAWS and Chrome/Edge/IE11, as well as NVDA and Chrome/Edge (but not NVDA and Firefox).

The bug is caused by absolute positioning which removes any whitespace before or after visually hidden text from the accessibility tree. This can lead to unintelligible screen reader announcements, such as the above mentioned GOV.UK search results heading being announced as "Searchall content", instead of "Search all content". The bug also impacts screen reader announcements when the visually hidden text appears before the visible text, for instance on the Foreign travel advice page where screen readers read the partly visually hidden heading as "Countries starting withA".

The actual issue can be seen by inspecting the accessibility tree value of the above <h1> on the search results page. Its value is "Search" (without the correct whitespace) with position: absolute included in .govuk-visually-hidden, but it is "Search " (with the correct whitespace) without absolute positioning.

The fix

To fix this, insert a space character before and after visually hidden text using pseudo elements to separate it from any visible text surrounding it. The fix tests well in all screen readers, regardless of whether the whitespace is before the visually hidden text ("Search all content"), after the visually hidden text ("Countries starting with A") or where the heading text is only made up visually hidden text ("Navigation menu"). The only slight issue I found is that Mac VoiceOver in Safari explicitly announces the inserted space characters when navigating by headings - but this is unlikely to block any users and the user numbers for MacOS VoiceOver are small compared to other assistive technologies. I also tested the fix where the visually hidden text appears as a part of a paragraph or a table cell. Please let me know if there are any other contexts I should test this in.

Before

Search all content is being read out as searchall content by JAWS

After

Search all content is now correctly read out by JAWS

Before

Screenshot 2023-06-15 at 11 22 59

After

Screenshot 2023-06-15 at 11 23 21

Testing results

Screen readers

✅ JAWS 2022 / Chrome
✅ JAWS 2023 / Chrome
✅ JAWS 2023 / IE 11
✅ JAWS 2023 / Edge
✅ NVDA / Firefox
✅ NVDA / Chrome
✅ NVDA / Edge
✅ Voiceover / Mac Safari
❎ Voiceover / iOS Safari
✅ Talkback / Chrome Android

iOS VoiceOver announces the visually hidden text separately but this issue is already present on live and has previously been reported here. Interestingly, the below mentioned aria-label solution fixes the issue in iOS (at least on headings; other contexts might not work so well) but has other significant problems as documented below.

Browsers and devices

I was testing that there is no visual difference in the element with the pseudo element space characters.

✅ Edge
✅ Firefox (Mac and Windows, and when user sets their own custom colours)
✅ Chrome (Mac and Windows)
✅ IE 11
✅ Safari Mac
✅ Safari iOS
✅ Samsung Internet (Android)
✅ Firefox (Android)
✅ Chrome (Android)
Samsung Internet
✅ Firefox (Android)

Other modes tested

✅ Print styles
✅ Hidden and unhidden like govuk-visually-hidden when CSS fails to load

Other fixes that were explored

I also looked into using opacity: 0 as a possible replacement for position: absolute. This tested well in all screen readers and browsers in terms of hiding the element but making it available to screen readers. However, the visually hidden text would remain part of the page flow, potentially causing issues by pushing visible page elements out of flow or down the page.

Another alternative, also explored here, would be to use a non-breaking space in the markup. This also tested well, but would always need to be inserted in the markup alongside the visually hidden text, making it more of a manual fix which could be accidentally removed by the next person working in the file (the process of inserting and enforcing the character could be be part of a build pipeline but this would introduce an unworkable overhead in many contexts).

I also explored using aria-label (for instance, "Search all content" for the search results heading), but the label does not get announced at all by JAWS and Mac VoiceOver on headings (even though it seems to be allowable content on headings); using it for paragraphs or table cells would be at least as unlikely to be announced consistently.

Notes to reviewers

I ended up including some examples of visually hidden text in the review app. They were helpful when testing but let me know if you'd rather I removed them. The table example specifically is a duplicate of the content on the bank holidays full page example so should probably be removed unless it's useful to have it in same place as the other visually hidden examples.

I'm comparing the PR with the support/4.6.x branch, let me know if that's not right.

Fixes alphagov/reported-bugs#51

Absolute positioning has the unintended consequence of removing any whitespace before or after visually hidden text from the accessibility tree. This can lead to unintelligible screen reader announcements, such as the GOV.UK search results heading being announced as "Searchall content", instead of "Search all content".

Insert a space character before and after visually hidden text using pseudo elements to ensure correct screen reader announcements of visually hidden text with surrounding whitespace. This tests well in all screen readers, regardless of whether the whitespace is before the visually hidden text ("Search all content"), after the visually hidden text ("Countries starting with A") or where the heading text is only made up visually hidden text ("Navigation menu"). The only slight issue I found is that Mac VoiceOver in Safari explicitly announces the inserted spare characters when navigating by headings - but this is unlikely to block any users and the user numbers for Mac VoiceOver are small compared to other assistive technologies.

I also looked into using `opacity: 0`, without `position: absolute` - this tested well in all screen readers and browsers, with the text visually hidden but accessible to assistive technologies. However, as it doesn't remove the element from the page flow, long visually hidden text would end up wrapping and pushing other elements down the page. Another alternative, also explored on the original ticket would be to use a non-breaking space &nbsp;. This also tested well, but would require always to be inserted in the markup along the visually hidden text, making it more of a manual fix which might also get accidentlaly removed by the next person working in the file. Another alternative would have been to use aria-label with "Search all content" but this doesn't get announced at all by JAWS and Mac VoiceOver (even though it fixes the iOS VoiceOver issue and seems to be allowable content on headings).
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3836 June 20, 2023 19:19 Inactive
@hannalaakso hannalaakso changed the base branch from main to support/4.6.x June 20, 2023 19:25
@colinrotherham colinrotherham changed the base branch from support/4.6.x to support/4.x June 21, 2023 08:43
@colinrotherham colinrotherham force-pushed the include-space-in-visually-hidden-text branch from d50d507 to 722e6b9 Compare June 21, 2023 08:45
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3836 June 21, 2023 08:45 Inactive
@colinrotherham
Copy link
Contributor

Thanks @hannalaakso this is great

I've changed the branch to support/4.x but only because we already have a v4.7.0 release planned

Would you mind double checking the HTML indentation? One of the checks has caught it

@colinrotherham colinrotherham added the awaiting triage Needs triaging by team label Jun 21, 2023
@hannalaakso hannalaakso force-pushed the include-space-in-visually-hidden-text branch from 722e6b9 to 4590118 Compare June 21, 2023 10:13
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3836 June 21, 2023 10:13 Inactive
@hannalaakso
Copy link
Member Author

Thanks @colinrotherham 👍 I've just fixed the indentation issue.

@owenatgov owenatgov added this to the v4.7.0 milestone Jun 23, 2023
Copy link
Contributor

@owenatgov owenatgov left a comment

Choose a reason for hiding this comment

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

This looks good to me.

As it's an external contribution thus needing 2 approvals, and to maintain review hierarchy, I'll re-request review from @colinrotherham.

@owenatgov owenatgov requested a review from colinrotherham June 27, 2023 15:04
@colinrotherham colinrotherham force-pushed the include-space-in-visually-hidden-text branch from 4590118 to 8d7d0eb Compare June 27, 2023 16:15
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3836 June 27, 2023 16:15 Inactive
Copy link
Contributor

@colinrotherham colinrotherham left a comment

Choose a reason for hiding this comment

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

Just pushed a few more tiny indent things but I'm happy when @owenatgov is happy 🙌

Thanks @hannalaakso

@owenatgov owenatgov merged commit 4d91b1b into support/4.x Jun 28, 2023
@owenatgov owenatgov deleted the include-space-in-visually-hidden-text branch June 28, 2023 09:28
tombye added a commit to alphagov/notifications-admin that referenced this pull request Nov 15, 2023
Borrowed from v5 of govuk-frontend which includes
the changes from this pull request to fix an issue
with how certain screen readers announce spaces in
visually hidden text:

alphagov/govuk-frontend#3836
frankieroberto added a commit to nhsuk/nhsuk-frontend that referenced this pull request Jun 8, 2024
… text

This fixes a bug in the nhsuk-u-visually-hidden helper class where any whitespace surrounding visually hidden text isn't announced by screen readers.

This fix was added to `govuk-frontend` in [pull request #3868](alphagov/govuk-frontend#3836) and has been re-applied here.

Thanks to @hannalaakso for the work upstream.

Co-Authored-By: hannalaakso <[email protected]>
frankieroberto added a commit to nhsuk/nhsuk-frontend that referenced this pull request Oct 15, 2024
… text

This fixes a bug in the nhsuk-u-visually-hidden helper class where any whitespace surrounding visually hidden text isn't announced by screen readers.

This fix was added to `govuk-frontend` in [pull request #3868](alphagov/govuk-frontend#3836) and has been re-applied here.

Thanks to @hannalaakso for the work upstream.

Co-Authored-By: hannalaakso <[email protected]>
frankieroberto added a commit to nhsuk/nhsuk-frontend that referenced this pull request Oct 17, 2024
… text (#960)

This fixes a bug in the nhsuk-u-visually-hidden helper class where any whitespace surrounding visually hidden text isn't announced by screen readers.

This fix was added to `govuk-frontend` in [pull request #3868](alphagov/govuk-frontend#3836) and has been re-applied here.

Thanks to @hannalaakso for the work upstream.

---------

Co-authored-by: hannalaakso <[email protected]>
Co-authored-by: anandamaryon1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

JAWS with Chrome links visually hidden text are read out without spaces
5 participants