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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions app/src/views/examples/typography/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,74 @@

</section>

<section class="govuk-!-margin-top-8">
<h2 class="govuk-heading-l govuk-!-padding-bottom-2" style="border-bottom: 4px solid;">Visually hidden text</h2>

<h3 class="govuk-heading-m">Heading with visually hidden text at the beginning</h3>

<h4 class="govuk-heading-s"><span class="govuk-visually-hidden">Countries starting with </span>A</h4>

<h3 class="govuk-heading-m">Heading with visually hidden text at the end</h3>

<h4 class="govuk-heading-s">Search <span class="govuk-visually-hidden">all content</span></h4>

<h3 class="govuk-heading-m">Heading that is visually hidden</h3>

<h4 class="govuk-visually-hidden">Navigation menu</h4>

<hr class="govuk-section-break govuk-section-break--visible govuk-section-break--xl">

<h3 class="govuk-heading-m">Paragraph that contains visually hidden text</h3>

<p class="govuk-body">This is a paragraph <span class="govuk-visually-hidden">with some visually hidden text</span>.</p>

<hr class="govuk-section-break govuk-section-break--visible govuk-section-break--xl">

<h3 class="govuk-heading-m">Table with visually hidden text</h3>

{{ govukTable({
caption: "2019",
captionClasses: "govuk-!-margin-bottom-4",
head: [
{
text: "Date",
classes: "govuk-visually-hidden"
},
{
text: "Day",
classes: "govuk-visually-hidden"
},
{
text: "Name",
classes: "govuk-visually-hidden"
}
],
rows: [
[
{
text: "19 April"
},
{
text: "Friday"
},
{
text: "Good Friday"
}
],
[
{
text: "22 April"
},
{
text: "Monday"
},
{
text: "Easter Monday"
}
]
]
}) }}
</section>
</div>
</div>
{% endblock %}
12 changes: 12 additions & 0 deletions src/govuk/helpers/_visually-hidden.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@
@mixin govuk-visually-hidden($important: true) {
position: absolute if($important, !important, null);

// Absolute positioning has the unintended consequence of removing any
// whitespace surrounding visually hidden text from the accessibility tree.
// Insert a space character before and after visually hidden text to separate
// it from any visible text surrounding it.
&:before {
content: "\00a0";
}

&:after {
content: "\00a0";
}

width: 1px if($important, !important, null);
height: 1px if($important, !important, null);
// If margin is set to a negative value it can cause text to be announced in
Expand Down