Skip to content

Commit

Permalink
♿️(styles) improve the offscreen class
Browse files Browse the repository at this point in the history
Change the implementation of the offscreen class to match the one from
bootstrap that is battle-tested.

The main idea is to stop using "left: -100000px" that can cause
scrolling "flicker" or weird focus styles when using a screen reader.
This can be annoying for sighted people that use a screen reader.
  • Loading branch information
manuhabitela committed Mar 22, 2022
1 parent 2af70ac commit 3482ca7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).
description with every markup removed
- Set font size to 1rem on some detail pages contents: Organization
excerpt, Program body and Person main content
- Improve the `offscreen` class implementation to prevent potential visual
issues for sighted user keyboards

### Fixed

Expand Down
33 changes: 16 additions & 17 deletions src/frontend/scss/generic/_accessibility.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@
// to users that need it.

// Screen reader only content
.offscreen {
position: absolute;
left: -10000px;
top: auto;
width: 1px;
height: 1px;
overflow: hidden;

// Screen reader toggleable function, including offscreen navigation
&:active,
&:focus {
left: 5px;
top: 5px;
width: auto;
height: auto;
overflow: auto;
}
// code taken from orange's fork of bootstrap
// https://github.com/Orange-OpenSource/Orange-Boosted-Bootstrap/blob/v5.1.3/scss/mixins/_visually-hidden.scss#L8
.offscreen,
.offscreen-focusable:not(:focus) {
position: absolute !important;
width: 1px !important;
height: 1px !important;
padding: 0 !important;
margin: -1px !important;
overflow: hidden !important;
clip: rect(0, 0, 0, 0) !important;
white-space: nowrap !important;
border: 0 !important;
}

// Skip to content button styles for it to be rendered on link focus
Expand All @@ -28,6 +24,9 @@
background-color: r-color('midnightblue');
padding: 1rem;
z-index: 100000;
position: absolute;
left: 5px;
top: 5px;

&:active,
&:hover,
Expand Down
2 changes: 1 addition & 1 deletion src/richie/apps/core/templates/richie/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

{# First link on a website should always be a skip to content #}
{# Access key directive allows users to use keyboard shortcuts #}
<a href="#site-content" class="offscreen skip-to-content" accesskey="c">{% trans "Skip to main content" %}</a>
<a href="#site-content" class="offscreen-focusable skip-to-content" accesskey="c">{% trans "Skip to main content" %}</a>

{% block body_header %}

Expand Down

0 comments on commit 3482ca7

Please sign in to comment.