[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 ...
随机推荐
- Android开机键失灵启动手机的解决的方法
问题描写叙述 Android手机的关机键损坏,无法开机. 解决方法 将手机通过USB线链接电脑,进入命令行.找到adb命令所在文件夹.执行例如以下命令: adb reboot 注意:用这样的方法的前提 ...
- Linux - 常用网络命令详解netstat,scp
ifconfig 查看生效的ip信息. [root@local ~]# ifconfig eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICA ...
- navicat数据库同步
10.168.95.246
- redis配置文件参数详解
配置文件参数说明: 1. Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程 daemonize no 2. 当Redis以守护进程方式运行时,Redis默认会把pi ...
- php !=和!==
今天测试了一下!=和!== <?phpheader("Content-type: text/html; charset=utf-8"); if (1!="1&quo ...
- python - 中文打印报错SyntaxError: Non-ASCII character '\xe4' in file test.py on line 3, but no encoding declared。
python中默认的编码格式是ASCII格式, 所以在没修改编码格式时无法正确打印汉字. 解决办法: 在以后的每一个需要显示汉字的python文件中, 可以采用如下方法在 #!/usr/bin/pyt ...
- Oracle表的种类及定义
1表的类型 1)堆组织表(heap organized tables). 当增加数据时,将使用在段中找到的第一个适合数据大小的空闲空间.当数据从表中删除时,留下的空间允许随后的insert和updat ...
- (转载)自定义CoordinatorLayout的Behavior(2):实现淘宝和QQ ToolBar透明渐变效果
自定义CoordinatorLayout的Behavior(2):实现淘宝和QQ ToolBar透明渐变效果 作者 小武站台 关注 2016.02.19 11:34 字数 1244 阅读 3885评论 ...
- android黑科技系列——微信抢红包插件原理解析和开发实现
一.前言 自从几年前微信添加抢红包的功能,微信的电商之旅算是正式开始正式火爆起来.但是作为Android开发者来说,我们在抢红包的同时意识到了很多问题,就是手动去抢红包的速度慢了,当然这些有很多原因导 ...
- 算法 之 3n+1问题
卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反复砍下去,最后一定在某一步得到n=1.卡拉兹在1950年的世界数 ...