Skip to content

Commit

Permalink
Merge branch 'master' of github.com:PublicisSapient/enable-a11y into …
Browse files Browse the repository at this point in the history
…jest
  • Loading branch information
zoltan-dulac committed Aug 11, 2022
2 parents bb5db31 + 38266ef commit 5e3d1f4
Show file tree
Hide file tree
Showing 66 changed files with 90,147 additions and 284 deletions.
4 changes: 2 additions & 2 deletions bin/checkHTML
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ echo "$OUTPUT" | (

# echo "LINES_INFO: $LINES_INFO"
# echo "LINE_NUM: $BEGIN_LINE_NUM $END_LINE_NUM"
printf "$LINE\n\n$CONTEXT\n\n"
echo -e "$LINE\n\n$CONTEXT\n\n"
else
printf "GLOBAL ERROR: $LINE\n\n"
echo -e "GLOBAL ERROR: $LINE\n\n"
fi
fi
done
Expand Down
2 changes: 1 addition & 1 deletion content/body/code-quality.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</p>
<p>
Enable has a non-public set of experimental unit tests that have been implemented. These haven't been released to the public yet due to us wanting to ensure the unit tests we give are a good model for developers to use in their own projects. In the meantime, <a href="https://www.24a11y.com/2017/writing-automated-tests-accessibility/">Writing Automated Tests for Accessibility</a> by <a href="https://www.deque.com/blog/author/marcy-sutton/">Marcie Sutton</a> is a great place to start (it's where we started).
Enable currently is testing out using <a href="https://jestjs.io/">Jest</a> with <a href="https://github.com/puppeteer/puppeteer">Puppeteer</a> to do unit tests. These tests haven't been released to the public yet because we haven't finished our testing, and we want to ensure the unit test advice we give are a good model for developers to use in their own projects. In the meantime, <a href="https://www.24a11y.com/2017/writing-automated-tests-accessibility/">Writing Automated Tests for Accessibility</a> by <a href="https://www.deque.com/blog/author/marcy-sutton/">Marcie Sutton</a> and <a href="https://medium.com/walkme-engineering/web-accessibility-testing-d499a7f7a032">Web Accessibility Testing</a> by <a href="https://www.kfirzuberi.com/">Kfir Zuberi</a> are great places to start (it's where we started).
</p>
Expand Down
131 changes: 131 additions & 0 deletions content/body/exposing-style-info-to-screen-readers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<p>On many websites, I have come across situations were text has been crossed out using the <code>&lt;del&gt;</code> or
<code>&lt;strike&gt;</code> tags. Unforunately, most browsers don't expose the role of these tags to screen readers,
so text coded with these tags can be confusing. Take for example, the product tile below.

<div id="example1" class="enable-example">
<a class="product-tile product-tile__bad-example"
href="https://www.useragentman.com/blog/2022/06/16/r-i-p-internet-explorer-a-hate-filled-love-letter/">
<div class="product-tile__badge">
<span class="badge-product">
Clearance Sale
</span>
</div>

<div class="product-tile__image-container">
<img class="product-tile__image" src="https://www.useragentman.com/blog/wp-content/uploads/2022/06/good-bad-thumb.jpg" alt=""
role="presentation" >
</div>

<div class="product-tile__name">
Internet Explorer T-Shirt
</div>

<div class="product-tile__price">
<del>$30.00</del> <ins>$10.00</ins>
</div>
</a>
</div>

<h2>CSS Generated Content To The Rescue</h2>

<p>
If you use a screen reader and tab into the product tile, more likely or not, your screen reader will announce
something like "Link, Clearance Sale. Internet Explorer T-Shirt
$30.00 $10.00". Screen reader users would not know that the $30.00 is crossed out to denote that the price has dropped to
$10.00. In order to fix this, developers can use CSS generated content as well as screen reader only text to insert
visually hidden text before
the striken price so screen reader users can understand that this was the old price.
</p>

<div id="example2" class="enable-example">
<a class="product-tile product-tile--good-example"
href="https://www.useragentman.com/blog/2022/06/16/r-i-p-internet-explorer-a-hate-filled-love-letter/">
<div class="product-tile__badge">
<span class="badge-product">
Clearance Sale
</span>
</div>

<div class="product-tile__image-container">
<img class="product-tile__image" src="https://www.useragentman.com/blog/wp-content/uploads/2022/06/good-bad-thumb.jpg" alt=""
role="presentation" >
</div>

<div class="product-tile__name">
Internet Explorer T-Shirt
</div>

<div class="product-tile__price">
<del>$30.00</del> <ins>$10.00</ins>
</div>
</a>
</div>

<p>Let's walk through how we ensure this stricken text is read correctly by screen readers and other assistive
technologies.</p>

<?php includeShowcode("example2")?>
<script type="application/json" id="example2-props">
{
"replaceHtmlRules": {},
"steps": [{
"label": "Use the del and ins tags to markup the old and new prices.",
"highlight": "%OPENCLOSECONTENTTAG%ins ||| %OPENCLOSECONTENTTAG%del",
"notes": "Note that we use <code>&lt;del&gt;</code> instead of <code>&lt;s&gt;</code> or <code>&lt;strike&gt;</code>. This is because <code>&lt;del&gt;</code> are semantic tags, and <code>&lt;s&gt;</code> is not, in the same way <a href=\"https://stackoverflow.com/questions/271743/whats-the-difference-between-b-and-strong-i-and-em\">developers should use strong tags instead of the b tag in HTML</a>"
},
{
"label": "Use ::before and ::after pseudo-elements to generate screen-reader only text",
"highlight": "%CSS%product-tile-css~ .product-tile--good-example del::before ||| %CSS%product-tile-css~ .product-tile--good-example ins::before",
"notes": ""
},
{
"label": "Visually hide the text generated in the previous step to ensure only screen readers can read the text",
"highlight": "%CSS%product-tile-css~ .product-tile--good-example del::before, .product-tile--good-example ins::before",
"notes": "Note that this uses similar CSS as the <a href=\"https://www.w3docs.com/snippets/css/why-and-how-the-bootstrap-sr-only-class-is-used.html\"><code>sr-only</code> class</a> to hide the CSS generated content visually. Note we also use <code>user-select: none</code> so users can't select the text when they are copying and pasting the content into, say, a word document. You may decide to leave that part out, if you wish."
}
]
}
</script>

<h2>How we use this in Enable</h2>

<p>
Highlighted text can also be marked up in a similar way to emphasize that it is highlighted. Take this example (which
is same markup we use in the code walkthroughs to highlight text):
</p>

<div id="highlight-example" class="enable-example">
<pre class="showcode__example"><code>
&lt;div&gt;
<mark class="showcode__highlight">&lt;del&gt;
$30.00
&lt;/del&gt;</mark>
&lt;/div&gt;
</code></pre>
</div>

<p>The code to generate the highlighted text is very similar to the one used for the stikethrough text example, except
we use both a <code>::before</code> and a <code>::after</code> rule:</p>

<?php includeShowcode("highlight-example")?>
<script type="application/json" id="highlight-example-props">
{
"replaceHtmlRules": {},
"steps": [{
"label": "Use the mark tag to highlight the text",
"highlight": "%OPENCLOSECONTENTTAG%mark",
"notes": "The <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/mark\">HTML <code>mark</code> tag</a> is the standard HTML tag you should use to highlight text."
},
{
"label": "Use ::before and ::after rules to have screen readers announce the text as highlighted",
"highlight": "%CSS%showcode-css~ .showcode__highlight::before ||| %CSS%showcode-css~ .showcode__highlight::after",
"notes": "Note we use <strong>both</strong> the <code>::before</code> and <code>::after</code> rules here. This is to ensure screen reader users know where the highlighted text begin and end, since it can be quite long."
},
{
"label": "Hide the CSS generated content from screen readers.",
"highlight": "%CSS%showcode-css~ .showcode__highlight::before, .showcode__highlight::after",
"notes": "Just like in the previous example, we hide the CSS generated content visually so only screen readers will read the content."
}
]
}
</script>
7 changes: 7 additions & 0 deletions content/body/faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@
please go to the <a href="https://github.com/PublicisSapient/enable-a11y/issues">Enable Github issue page</a> and
opening up a new issue describing the code you would like to donate and a sample page on how it works.</dd>
<dt>Do you have any advice on how I can add automated accessibility testing to my CI/CD pipeline?</dt>
<dd>
Enable uses a few tools to find the 20% to 50% of accessibility errors that can be captured by automated tools. We also have
started to do unit testing to ensure that accessibility features added to our components are not removed by accident.
To understand more about what tools we use and how we have done this, please read our page on <a href="code-quality.php">
Accessible Code Quality
</a>.
</dl>
129 changes: 112 additions & 17 deletions content/body/focus-styling.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<?php includeShowcode("focus-remove", "", "", "", false)?>

<figcaption>Figure 1. Horrible code a lot of developers use to turn off focus states. Never do this.</figcaption>
<figcaption>Figure 1. Horrible code a lot of developers use to turn off focus states. Never do this.</figcaption>


</figure>
Expand All @@ -34,7 +34,7 @@
</script>

<template id="focus-remove" data-type="css">
*:focus { outline: none; }
*:focus { outline: none; }
</template>

<p>
Expand All @@ -55,7 +55,8 @@
<figure class="wide">
<?php includeShowcode("css-focus-visible", "", "", "", false)?>

<figcaption>Figure 2. Much better code that styles focus states for keyboard users, while minimizing its visibility for mouse users.</figcaption>
<figcaption>Figure 2. Much better code that styles focus states for keyboard users, while minimizing its visibility
for mouse users.</figcaption>
</figure>

<script type="application/json" id="css-focus-visible-props">
Expand Down Expand Up @@ -99,12 +100,11 @@
</p>


<figure>
<figure class="wide centered-image">

<?php pictureWebpPng("images/focus/clickable-hit-state", "Screenshot of the Enable website's main navigation, with keyboard focus applied to the 'controls' navigation drawer.")?>

<figcaption>Figure 3. The focus state of the "Contols" navigation button. Note that the hit area is a lot larger than
the visual height of the thin horizontal gray strip where the drawer sits inside.</figcaption>
<figcaption>Figure 3. The focus state of the "Contols" navigation button. Note the large hit area.</figcaption>
</figure>

<p>We increased the hit area to conform to <a href="https://www.w3.org/WAI/WCAG21/Understanding/target-size.html">WCAG
Expand Down Expand Up @@ -134,7 +134,8 @@
<h2>Issues with CSS Transitions and CSS outline in Safari</h2>

<p>
On a few projects, I have noticed that Safari focus states don't appear correctly when the element that is focused has the following CSS applied to it:
On a few projects, I have noticed that Safari focus states don't appear correctly when the element that is focused has
the following CSS applied to it:
</p>

<figure class="wide">
Expand All @@ -156,16 +157,23 @@

<template id="transition-all-code" data-type="css">
a {
transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
</template>

<p>
The above CSS can mess up Safari focus states: they may appear cut off or may not appear at all in Safari, while they may appear fine in other web browsers. <strong>The correct way to fix this is to <em>never</em> use <code> transition: all</code> in your CSS.</strong> Using <code>all</code>. There are many reasons why you should never use not use the <code>all</code> keyword for transitions (in this case, because of unwanted side-effects, but also for performance reasons). <a href="https://www.pno.dev/">Philipp Nowinski</a> has written a great write-up on <a href="https://www.pno.dev/articles/dont-use-the-all-keyword-in-css-transitions/">why you shouldn't use the 'all' keyword in CSS transitions</a>, and I suggest all developers read this.
The above CSS can mess up Safari focus states: they may appear cut off or may not appear at all in Safari, while they
may appear fine in other web browsers. <strong>The correct way to fix this is to <em>never</em> use
<code> transition: all</code> in your CSS.</strong> Using <code>all</code>. There are many reasons why you should
never use not use the <code>all</code> keyword for transitions (in this case, because of unwanted side-effects, but
also for performance reasons). <a href="https://www.pno.dev/">Philipp Nowinski</a> has written a great write-up on <a
href="https://www.pno.dev/articles/dont-use-the-all-keyword-in-css-transitions/">why you shouldn't use the 'all'
keyword in CSS transitions</a>, and I suggest all developers read this.
</p>

<p>
If removing the <code>all</code> transition code will cause problems in your project, you can use the following hack to fix the code in Safari:
If removing the <code>all</code> transition code will cause problems in your project, you can use the following hack
to fix the code in Safari:
</p>

<figure class="wide">
Expand All @@ -186,29 +194,33 @@
</script>

<template id="fix-transition-all-code" data-type="css">
@media screen and (-webkit-min-device-pixel-ratio:0) {
@media screen and (-webkit-min-device-pixel-ratio:0) {

/* Safari only*/
*:focus { transition: none !important; }

}
}
</template>


<p>
Note that <strong>it is much better to remove the <code>all</code> keyword and just transtition what you need instead.</strong> This solution should only be a band-aid solution until you can fix the issue properly.
Note that <strong>it is much better to remove the <code>all</code> keyword and just transtition what you need
instead.</strong> This solution should only be a band-aid solution until you can fix the issue properly.
</p>


<h2>Don't Forget Windows High Contrast Mode Users.</h2>

Sometimes, you will want to style focus states without the CSS <code>outline</code> property. If you do this, but instead of using <code>outline: none</code> to remove the default focus ring, developers should use outline with the <code>transparent</code> colour:
Sometimes, you will want to style focus states without the CSS <code>outline</code> property. If you do this, but
instead of using <code>outline: none</code> to remove the default focus ring, developers should use outline with the
<code>transparent</code> colour:


<figure class="wide">
<?php includeShowcode("transparent-outline-code", "", "", "", false)?>

<figcaption>Figure 6. Adding a transparent outline along with your custom focus state that doesn't have an outline</figcaption>
<figcaption>Figure 6. Adding a transparent outline along with your custom focus state that doesn't have an outline
</figcaption>
</figure>

<script type="application/json" id="transparent-outline-code-props">
Expand All @@ -223,5 +235,88 @@
</script>

<template id="transparent-outline-code" data-type="css">
button.special-style:focus { outline: transparent 2px solid; border-bottom: 2px solid #00f; }
</template>
button.special-style:focus { outline: transparent 2px solid; border-bottom: 2px solid #00f; }
</template>

<h2>Guaranteed Contrast on Focus Rings, Regardless of Background</h2>

<p>
If you don't know what colour background your focus rings will be on top of, there is a simple way of ensuring your
focus rings will follow contrast rules: using <code>outline</code> and <code>box-shadow</code> at the same time.
</p>

<p>
Here is an example you can tab into to see this combo in action:
</p>

<div id="double-focus-ring-example" class="enable-example">
<p>
<a href="#">This is a dummy link</a>
<a href="#">This is a dummy link</a>
<a href="#">This is a dummy link</a>
<a href="#">This is a dummy link</a>
<a href="#">This is a dummy link</a>
<a href="#">This is a dummy link</a>
<a href="#">This is a dummy link</a>
</p>
</div>

<p>
If you are using a mobile device, here are some screenshots you can look at to show how it looks:
</p>


<figure class="wide centered-image">
<table class="screenshot-table" aria-labelledby="double-focus-screenshot-table-caption">

<thead>
<tr>
<th scope="col">
Focus State
</th>
<th scope="col">
Screenshot
</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">No Element is Focused</th>
<td>
<?php pictureWebpPng("images/focus/double-focus-ring__initial-state", "Two yellow blocky interactive elements on a gradient background. The gradient is starts on a light yellow on the left and ends with a darker red on the right.", ""); ?>
</td>
</tr>
<tr>
<th scope="row">Focus on Lighter Area of Gradient</th>
<td>
<?php pictureWebpPng("images/focus/double-focus-ring__light-bg", "The same interactive elements on the same gradient background. The interactive element on the left is focused, and the blue focus outline around it is easily seen in contrast with the light background.", ""); ?>
</td>
</tr>
<tr>
<th scope="row">Focus on Darker Area of Gradient</th>
<td>
<?php pictureWebpPng("images/focus/double-focus-ring__darker-bg", "The same interactive elements on the same gradient background. The interactive element on the right is now focused, and the white box shadow that appears outside the darker blue focus outline ensures the focus ring has enough contrast with the dark background.", ""); ?>
</td>

</tr>
</tbody>
</table>

<figcaption id="double-focus-screenshot-table-caption">Figure 7. Dual-Coloured Focus States on a Gradient Background</figcaption>
</figure>

<p>Here is the markup that implements the double focus ring. Notice the use of both <code>outline</code> and <code>box-shadow</code> to create this effect (the box-shadow offsets must be greater than the outline thickness in order for this to work):</p>

<?php includeShowcode("double-focus-ring-example", "", "", "", false)?>
<script type="application/json" id="double-focus-ring-example-props">
{
"replaceHtmlRules": {
},
"steps": [
{
"label": "Implement the double focus ring",
"highlight": "%CSS%focus-styling-css~ #double-focus-ring-example *:focus-visible",
"notes": ""
}
]}
</script>
2 changes: 1 addition & 1 deletion content/body/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-->
</div>
</div>

<div class="with-full-bleed-hero__content">

<div class="homepage__intro">
Expand Down
2 changes: 2 additions & 0 deletions content/body/table.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

</ul>

<h2>How Screen Reader Users Navigate Tables</h2>

<p>Screen-reader users should be able to navigate the table using their screen-reader's built in navigation:
</p>

Expand Down
Loading

0 comments on commit 5e3d1f4

Please sign in to comment.