This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 876
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hides an element visually while still allowing the content to be accessible to assistive technology, e.g. screen readers
- Loading branch information
Showing
4 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
@charset "UTF-8"; | ||
|
||
/// Hides an element visually while still allowing the content to be accessible | ||
/// to assistive technology, e.g. screen readers. Passing `unhide` will reverse | ||
/// the affects of the hiding, which is handy for showing the element on focus, | ||
/// for example. | ||
/// | ||
/// @link http://goo.gl/Vf1TGn | ||
/// | ||
/// @argument {string} $toggle [hide] | ||
/// Accepts `hide` or `unhide`. `unhide` reverses the affects of `hide` | ||
/// | ||
/// @example scss | ||
/// .element { | ||
/// @include hide-visually; | ||
/// | ||
/// &:active, | ||
/// &:focus { | ||
/// @include hide-visually(unhide); | ||
/// } | ||
/// } | ||
/// | ||
/// @example css | ||
/// .element { | ||
/// border: 0; | ||
/// clip: rect(1px, 1px, 1px, 1px); | ||
/// clip-path: circle(1% at 1% 1%); | ||
/// height: 1px; | ||
/// overflow: hidden; | ||
/// padding: 0; | ||
/// position: absolute; | ||
/// width: 1px; | ||
/// } | ||
/// | ||
/// .hide-visually:active, | ||
/// .hide-visually:focus { | ||
/// clip: auto; | ||
/// clip-path: none; | ||
/// height: auto; | ||
/// overflow: visible; | ||
/// position: static; | ||
/// width: auto; | ||
/// } | ||
/// | ||
/// @since 5.0.0 | ||
|
||
@mixin hide-visually($toggle: hide) { | ||
@if $toggle == "hide" { | ||
border: 0; | ||
clip: rect(1px, 1px, 1px, 1px); | ||
clip-path: circle(1% at 1% 1%); | ||
height: 1px; | ||
overflow: hidden; | ||
padding: 0; | ||
position: absolute; | ||
width: 1px; | ||
} @elseif $toggle == "unhide" { | ||
clip: auto; | ||
clip-path: none; | ||
height: auto; | ||
overflow: visible; | ||
position: static; | ||
width: auto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require "spec_helper" | ||
|
||
describe "hide-visually" do | ||
before(:all) do | ||
ParserSupport.parse_file("addons/hide-visually") | ||
end | ||
|
||
context "called on element" do | ||
it "adds properties to hide the element" do | ||
ruleset = "border: 0; " + | ||
"clip: rect(1px, 1px, 1px, 1px); " + | ||
"clip-path: circle(1% at 1% 1%); " + | ||
"height: 1px; " + | ||
"overflow: hidden; " + | ||
"padding: 0; " + | ||
"position: absolute; " + | ||
"width: 1px;" | ||
|
||
expect(".hide-visually").to have_ruleset(ruleset) | ||
end | ||
end | ||
|
||
context "called with unhide argument" do | ||
it "adds properties to reverse the hiding of the element" do | ||
ruleset = "clip: auto; " + | ||
"clip-path: none; " + | ||
"height: auto; " + | ||
"overflow: visible; " + | ||
"position: static; " + | ||
"width: auto;" | ||
|
||
expect(".hide-visually--unhide").to have_ruleset(ruleset) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@import "setup"; | ||
|
||
.hide-visually { | ||
@include hide-visually; | ||
} | ||
|
||
.hide-visually--unhide { | ||
@include hide-visually(unhide); | ||
} |