Accessibly control an element's visibility across a range of breakpoints.
Please note: this plugin is optimised for internal Chrometoaster use. YMMV.
cd /PATH/TO/PROJECT-THEME-FOLDER
bower install https://github.com/chrometoasters/ct-jquery-ariaHiddenBreakrange.git#v1.0.11 --save
Note: if you wish to customise where Bower puts installed components, you may add a .bowerrc
file into this folder:
{
"directory" : "PATH/TO/COMPONENTS"
}
ct-jquery-ariaHiddenBreakrange.css
contains .no-js
rules to dynamically show and hide $('[data-ariaHiddenBreakrange]')
elements at the appropriate breakpoint.
This is a fallback for noscript users. It is inaccessible as there is no communication to a screenreader that an element is hidden, only a visual indicator for sighted users.
ct-jquery-ariaHiddenBreakrange.css
sets elements with aria-hidden="true"
to display:none
.
On initial load, and when the viewport is resized, $('[data-ariaHiddenBreakrange]')
elements are dynamically shown and hidden by setting and changing the value of their WAI-ARIA aria-hidden
attribute.
This is the most accessible way to hide elements, as the accessibility API can communicate to a screenreader that an element is hidden, in addition to the visual indicator for sighted users.
Note: to apply display:inline
rather than display:block
when an element is visible, use ariaHiddenBreakrange
with a span
element.
When JavaScript is disabled, a parent element (typically the html
element) should include the noscript flag .no-js
. This flag should be removed via JavaScript.
Include the following HTML for MSIE and noscript support:
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if IE 9]> <html class="no-js lt-ie10"> <![endif]-->
<!--[if gt IE 9]><!--> <html class="no-js"> <!--<![endif]-->
Specify an element to hide within a particular breakrange:
<div data-ariaHiddenBreakrange="mobile,tablet">Some text for desktop and wider</div>
Then call the JavaScript function with the default options like so:
$('[data-ariaHiddenBreakrange]').ariaHiddenBreakrange();
Ensure that the following assets are available on your page:
jquery.js/jquery.min.js
(dependency, via Bower)media-match/media.match.min.js
(polyfill dependency, via Bower)enquire.js/dist/enquire.min.js
(dependency, via Bower)dist/ct-jquery-ariaHiddenBreakrange.css
(styles, bundled)dist/ct-jquery-ariaHiddenBreakrange.min.js
(script, bundled)Please refer to demos/ct-jquery-ariaHiddenBreakrange.html
.
Please run test/index-responsive.html
.
As this is the first release of this plugin there are some limitations:
mobile,tablet,desktop,desktop-wide
16px