JSFiddle - React, Tailwind, and code Playground
HTML
<form class="search-form">
<label class="keyword-search-input-label" for="keyword-search-input">
<span class="hide">Search</span>
<input class="form-control" type="text" id="keyword-search-input" name="keyword"/>
</label>
<button id="clear-field-button" type="reset">
<span class="hide">Clear Search Field</span>
</button>
<button id="search-button" type="submit" aria-describedby="number-found-items">
<span class="symbol-label">Search</span>
</button>
</form>
<div id="number-found-items">
<span id="number-found">0</span>
items found
</div>
CSS
.offscreen {
border: 0;
clip: rect(0 0 0 0);
clip: rect(0, 0, 0, 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
width: 1px;
position: absolute;
}
JavaScript
var $numberFound = $('#number-found');
$('#search-button').on('click', function(event) {
event.preventDefault();
window.setTimeout(function() {
var value = getRandomInt(0, 100);
jQuery.a11yfy. assertiveAnnounce(value + ' items found');
updateNumberFound(value);
}, 1000);
});
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function updateNumberFound(value) {
$numberFound.text(value || 0);
}
/**
*
* jQuery module for accessibility
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Dylan Barrell
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
(function (jQuery){
var $politeAnnouncer = jQuery("#jquery-a11yfy-politeannouncer"),
$assertiveAnnouncer = jQuery("#jquery-a11yfy-assertiveannouncer"),
methods = {
showAndFocus: function(focus) {
var $focus = focus ? jQuery(focus) : focus;
return this.each(function...