[HTML5] Accessibility Implementation for complex component
When you developing a complex component by your own, one thing you cannot ignore is Accessibility.
Checkout this link. It lists all things you need to do regarding to accessibility when implements a complex component.
The tech we are using is: Roving Focus
Take radio group as an example, when doing roving focus, we set current focus element's:
tabindex = "0 " checked="checked"
And set other elements to:
tabindex="-1"
(function() {
'use strict'; // Define values for keycodes
var VK_ENTER = 13;
var VK_SPACE = 32;
var VK_LEFT = 37;
var VK_UP = 38;
var VK_RIGHT = 39;
var VK_DOWN = 40; // Helper function to convert NodeLists to Arrays
function slice(nodes) {
return Array.prototype.slice.call(nodes);
} function RadioGroup(id) {
this.el = document.querySelector(id);
this.buttons = slice(this.el.querySelectorAll('.radio'));
this.focusedIdx = 0;
this.focusedButton = this.buttons[this.focusedIdx]; this.el.addEventListener('keydown', this.handleKeyDown.bind(this));
} RadioGroup.prototype.handleKeyDown = function(e) {
switch(e.keyCode) { case VK_UP:
case VK_LEFT: { e.preventDefault(); // This seems like a good place to do some stuff :)
if(this.buttons && this.buttons.length && this.focusedIdx > 0) {
this.focusedIdx -= 1;
} else if(this.buttons && this.buttons.length && this.focusedIdx === 0) {
this.focusedIdx = this.buttons.length - 1;
}
break; } case VK_DOWN:
case VK_RIGHT: { e.preventDefault(); // This seems like a good place to do some stuff :)
if(this.buttons && this.buttons.length && this.focusedIdx < this.buttons.length - 1) {
this.focusedIdx += 1;
} else if(this.buttons && this.buttons.length && this.focusedIdx === this.buttons.length - 1) {
this.focusedIdx = 0;
} break;
} } this.changeFocus(this.focusedIdx); // <-- Hmm, interesting...
}; RadioGroup.prototype.changeFocus = function(idx) {
// Set the old button to tabindex -1
this.focusedButton.tabIndex = -1;
this.focusedButton.removeAttribute('checked'); // Set the new button to tabindex 0 and focus it
this.focusedButton = this.buttons[idx];
this.focusedButton.tabIndex = 0;
this.focusedButton.focus();
this.focusedButton.setAttribute('checked', 'checked');
}; var group1 = new RadioGroup('#group1'); }());
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="main.css">
</head>
<body> <div class="demo"> <h3>Drink Options</h3> <ul id="group1" class="radiogroup">
<li tabindex="0" class="radio" checked>
Water
</li>
<li tabindex="-1" class="radio">
Tea
</li>
<li tabindex="-1" class="radio">
Coffee
</li>
<li tabindex="-1" class="radio">
Cola
</li>
<li tabindex="-1" class="radio">
Ginger Ale
</li>
</ul> </div> <script src="radiogroup.js"></script> </body>
</html>
[HTML5] Accessibility Implementation for complex component的更多相关文章
- 说说HTML5中label标签的可访问性问题——张鑫旭
一.开篇叨叨 一般稍微有些经验的页面制作人员都知道label标签可以优雅地扩大表单控件元素的点击区域,例如,单纯的单选框点击区域就鼻屎那么大的地方,经常会点不到位置.因此,label标签的使用对于提高 ...
- (转) [it-ebooks]电子书列表
[it-ebooks]电子书列表 [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...
- Frontend Development
原文链接: https://github.com/dypsilon/frontend-dev-bookmarks Frontend Development Looking for something ...
- OSCP Learning Notes - Privilege Escalation
Privilege Escalation Download the Basic-pentesting vitualmation from the following website: https:// ...
- Windows Automation API 3.0 Overview
https://www.codemag.com/article/0810042 While general accessibility requirements (such as font color ...
- 【转】 Understanding Component-Entity-Systems
http://www.gamedev.net/page/resources/_/technical/game-programming/understanding-component-entity-sy ...
- WordPress 主题开发 - (四) 创建WordPress的主题HTML结构 待翻译
Now we're starting to get into the real meat of WordPress Theme development: coding the HTML structu ...
- jquery bootgrid 一个很好的 数据控件,可用于任何语言
http://www.jquery-bootgrid.com/Examples#command-buttons 效果很好,http://www.open-open.com/lib/view/open1 ...
- 【转】谈谈Google Polymer以及Web UI框架的未来
原文转自:http://www.csdn.net/article/2013-05-27/2815450-google-polymer 摘要:开发者Axel Rauschmayer在自己的博客上详解了G ...
随机推荐
- udev详解【转】
本文转载自:http://blog.csdn.net/skyflying2012/article/details/9359185 如果你使用Linux比较长时间了,那你就知道,在对待设备文件这块,Li ...
- 让git for windows记住密码
store 执行这个命令git config --global credential.helper store 检查命令是否成功 $ git config -l | grep credentialcr ...
- hdoj--1083--Courses(最大匹配)
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- 【POJ 2286】 The Rotation Game
[题目链接] http://poj.org/problem?id=2286 [算法] IDA* [代码] #include <algorithm> #include <bitset& ...
- Solr.NET快速入门(七)【覆盖默认映射器,NHibernate集成】
覆盖默认映射器 默认情况下,SolrNet使用属性映射Solr字段. 但是,您可能需要使用另一个映射程序. 替换默认映射器取决于您如何设置库: 内置容器 如果使用默认的内置容器,可以在调用Startu ...
- AJAX异步删除操作
@Ajax.ActionLink("删除", "Delete", new {id = user.Id}, ajaxOption) @{ var ajaxOpti ...
- 使用WebGL + Three.js制作动画场景
使用WebGL + Three.js制作动画场景 3D图像,技术,打造产品,还有互联网:这些只是我爱好的一小部分. 现在,感谢WebGL的出现-一个新的JavaScriptAPI,它可以在不依赖任何插 ...
- textarea 自适应高度
试了好多方法,包括百度了好多.一旦接口获取的内容,就不好用了.有时候就是脑袋转不过来,想了好久的方法居然那么简单,然后,脑洞大开,忽然想到还可以这样弄, 很简单,两句话 var textareaHei ...
- Wireshark抓包过滤
主要说明下抓包前准备工作,及wireshark里面的两个过滤器:捕获过滤器和应用显示过滤器 1.捕获过滤器.顾名思义就是捕获时的过滤器.主要用来决定你要抓包抓哪个IP哪个端口,明确自己要抓哪个IP和端 ...
- Win7系统下调整硬盘分区大小给C盘更多的空间
电脑安装了很多程序,C盘空间越来越小了.如何给C盘调整更多的空间,其实只要调整硬盘分区大小便可解决这个问题,下面有个小技巧,需要的朋友照做就可以了 Win7系统下如何调整硬盘分区大小,以前装系统的时候 ...