Skip to content

Commit

Permalink
Merge pull request #220 from hypothesis/a11y-css
Browse files Browse the repository at this point in the history
Bring accessibility- and focus-related mixins and utils into package
  • Loading branch information
lyzadanger authored Oct 21, 2021
2 parents 69ecd03 + a28da7c commit 3b0cbdc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions styles/mixins/_a11y.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Hide content from sighted users but make it visible to screen readers.
//
// Resources:
// - https://webaim.org/techniques/css/invisiblecontent/ (see "CSS clip")
// - https://cloudfour.com/thinks/see-no-evil-hidden-content-and-accessibility/#showing-additional-content-for-screen-readers
@mixin screen-reader-only {
// Take the content out of the normal layout flow.
position: absolute;
width: 1px;
height: 1px;
white-space: nowrap;

// Visually hide the content and prevent it from interfering with mouse/touch
// text selection by clipping it to an empty box. Compared to moving content with
// `top`/`left` this is less likely to cause the browser to scroll to a
// different part of the page when the hidden text has screen-reader focus.
clip: rect(0 0 0 0);
overflow: hidden;
}
5 changes: 5 additions & 0 deletions styles/util/_a11y.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@use '../mixins/a11y';

.hyp-u-screen-reader-only {
@include a11y.screen-reader-only;
}
12 changes: 12 additions & 0 deletions styles/util/_focus.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@
.hyp-u-focus-outline--inset {
@include focus.outline($inset: true);
}

.hyp-u-focus-outline--hide {
@include focus.outline--hide;
}

.hyp-u-outline-on-keyboard-focus {
@include focus.outline-on-keyboard-focus;
}

.hyp-u-outline-on-keyboard-focus--inset {
@include focus.outline-on-keyboard-focus($inset: true);
}
1 change: 1 addition & 0 deletions styles/util/index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@use 'a11y';
@use 'atoms';
@use 'colors';
@use 'focus';
Expand Down

0 comments on commit 3b0cbdc

Please sign in to comment.