Skip to content

Commit d5456e0

Browse files
authored
Merge pull request #4027 from alphagov/port-visually-hidden-whitespace-improvement
Port visually hidden whitespace announcement improvement
2 parents 43968b8 + 2d24e73 commit d5456e0

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

packages/govuk-frontend-review/src/views/examples/typography/index.njk

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,74 @@
536536

537537
</section>
538538

539+
<section class="govuk-!-margin-top-8">
540+
<h2 class="govuk-heading-l govuk-!-padding-bottom-2" style="border-bottom: 4px solid;">Visually hidden text</h2>
541+
542+
<h3 class="govuk-heading-m">Heading with visually hidden text at the beginning</h3>
543+
544+
<h4 class="govuk-heading-s"><span class="govuk-visually-hidden">Countries starting with </span>A</h4>
545+
546+
<h3 class="govuk-heading-m">Heading with visually hidden text at the end</h3>
547+
548+
<h4 class="govuk-heading-s">Search <span class="govuk-visually-hidden">all content</span></h4>
549+
550+
<h3 class="govuk-heading-m">Heading that is visually hidden</h3>
551+
552+
<h4 class="govuk-visually-hidden">Navigation menu</h4>
553+
554+
<hr class="govuk-section-break govuk-section-break--visible govuk-section-break--xl">
555+
556+
<h3 class="govuk-heading-m">Paragraph that contains visually hidden text</h3>
557+
558+
<p class="govuk-body">This is a paragraph <span class="govuk-visually-hidden">with some visually hidden text</span>.</p>
539559

560+
<hr class="govuk-section-break govuk-section-break--visible govuk-section-break--xl">
561+
562+
<h3 class="govuk-heading-m">Table with visually hidden text</h3>
563+
564+
{{ govukTable({
565+
caption: "2019",
566+
captionClasses: "govuk-!-margin-bottom-4",
567+
head: [
568+
{
569+
text: "Date",
570+
classes: "govuk-visually-hidden"
571+
},
572+
{
573+
text: "Day",
574+
classes: "govuk-visually-hidden"
575+
},
576+
{
577+
text: "Name",
578+
classes: "govuk-visually-hidden"
579+
}
580+
],
581+
rows: [
582+
[
583+
{
584+
text: "19 April"
585+
},
586+
{
587+
text: "Friday"
588+
},
589+
{
590+
text: "Good Friday"
591+
}
592+
],
593+
[
594+
{
595+
text: "22 April"
596+
},
597+
{
598+
text: "Monday"
599+
},
600+
{
601+
text: "Easter Monday"
602+
}
603+
]
604+
]
605+
}) }}
606+
</section>
540607
</div>
541608
</div>
542609
{% endblock %}

packages/govuk-frontend/src/govuk/helpers/_visually-hidden.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
@mixin govuk-visually-hidden($important: true) {
1717
position: absolute if($important, !important, null);
1818

19+
// Absolute positioning has the unintended consequence of removing any
20+
// whitespace surrounding visually hidden text from the accessibility tree.
21+
// Insert a space character before and after visually hidden text to separate
22+
// it from any visible text surrounding it.
23+
&::before {
24+
content: "\00a0";
25+
}
26+
27+
&::after {
28+
content: "\00a0";
29+
}
30+
1931
width: 1px if($important, !important, null);
2032
height: 1px if($important, !important, null);
2133
// If margin is set to a negative value it can cause text to be announced in

0 commit comments

Comments
 (0)