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的更多相关文章

  1. 说说HTML5中label标签的可访问性问题——张鑫旭

    一.开篇叨叨 一般稍微有些经验的页面制作人员都知道label标签可以优雅地扩大表单控件元素的点击区域,例如,单纯的单选框点击区域就鼻屎那么大的地方,经常会点不到位置.因此,label标签的使用对于提高 ...

  2. (转) [it-ebooks]电子书列表

    [it-ebooks]电子书列表   [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...

  3. Frontend Development

    原文链接: https://github.com/dypsilon/frontend-dev-bookmarks Frontend Development Looking for something ...

  4. OSCP Learning Notes - Privilege Escalation

    Privilege Escalation Download the Basic-pentesting vitualmation from the following website: https:// ...

  5. Windows Automation API 3.0 Overview

    https://www.codemag.com/article/0810042 While general accessibility requirements (such as font color ...

  6. 【转】 Understanding Component-Entity-Systems

    http://www.gamedev.net/page/resources/_/technical/game-programming/understanding-component-entity-sy ...

  7. WordPress 主题开发 - (四) 创建WordPress的主题HTML结构 待翻译

    Now we're starting to get into the real meat of WordPress Theme development: coding the HTML structu ...

  8. jquery bootgrid 一个很好的 数据控件,可用于任何语言

    http://www.jquery-bootgrid.com/Examples#command-buttons 效果很好,http://www.open-open.com/lib/view/open1 ...

  9. 【转】谈谈Google Polymer以及Web UI框架的未来

    原文转自:http://www.csdn.net/article/2013-05-27/2815450-google-polymer 摘要:开发者Axel Rauschmayer在自己的博客上详解了G ...

随机推荐

  1. TCP三次握手及关闭时的2MSL分析

    TCP/IP三次握手四次挥手,是非常重要的,这个链接与关闭过程也是非常easy的.但为什么是三次握手?以及为什么要等待2MSL的状态?大部分人或许听到这个问题就蒙了.这篇博客就综合<TCP/IP ...

  2. 给统计人讲Python(1)_科学计算库-Numpy

    本地代码是.ipynb格式的转换到博客上很麻烦,这里展示部分代码,了解更多可以查看我的git-hub:https://github.com/Yangami/Python-for-Statisticia ...

  3. MYSQL5.6和5.7编译标准化安装与配置

    文档结构图如下: 一.前期规划 1.软件环境以及说明 操作系统:RedHat Linux 6.7 64位 数 据 库:MYSQL5.6.38/5.7.20 MySQL 5.6:初始化数据时需要进到家目 ...

  4. LVS十种调度算法介绍

    1.轮叫调度(Round Robin)(简称rr) 轮叫调度(Round Robin Scheduling)算法就是以轮叫的方式依次将请求调度不同的服务器,即每次调度执行i = (i + 1) mod ...

  5. B - Ultra-Fast Mathematician

    Problem description Shapur was an extremely gifted student. He was great at everything including Com ...

  6. CI中的url相关函数以及路由设置和伪静态技术

    当使用CI框架进行开发时,我们的一些数据传递的URL不应该写死,可以使用如下方法:比如说我们需要表单提交一个数据: 1.在controller控制器中我们需要先创建一个加载helper和视图的方法: ...

  7. 给<hr/>添加样式

    点线式 破折线式 直线式 双线式 脊线式 槽线式 内嵌效果的 突起效果的 border-top:10px 设置水平线的大小 <hr style=" border-top:5px dot ...

  8. 利用JavaScript制作简易日历

    <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <met ...

  9. 杭电 1021 Fibonacci Again

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1021 解题思路:根据之前发现斐波那契数列的规律,即为f(n)能被3整除当且仅当n能被4整除. 于是联想 ...

  10. In-Out Parameters inout keyword

    You write an in-out parameter by placing the inout keyword right before a parameter’s type. An in-ou ...