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. element-UI中table表格的@row-click事件和@selection-change耦合了

    <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark&quo ...

  2. IJKPlayer问题集锦之不定时更新

    1.IJKPlayer 不像系统播放器会给你旋转视频角度,所以你需要通过onInfo的what == IMediaPlayer.MEDIA_INFO_VIDEO_ROTATION_CHANGED去获取 ...

  3. hdoj--3072--Intelligence System(scc+缩点+数据去重)

    Intelligence System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  4. 【转】iOS程序自动检测更新的实现 -- 思路不错

    原文网址:http://blog.csdn.net/davidsph/article/details/8931718 之前项目需要用到app自动更新的功能,现将实现方案分享出来.iOS程序自动提示更新 ...

  5. Java-Maven:Maven清单

    ylbtech-Java-Maven:Maven清单 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http ...

  6. JavaScript:DOM对象

    ylbtech-JavaScript:DOM对象 1. HTML DOM Document 对象返回顶部 1. HTML DOM Document 对象 HTML DOM 节点 在 HTML DOM ...

  7. [牛客挑战赛 30D] 小A的昆特牌 解题报告 (组合数学)

    interlinkage: https://ac.nowcoder.com/acm/contest/375/D description: solution: 我们枚举步兵的数量$x$,还剩下$S-x$ ...

  8. javascript设计模式-单体模式

    场景:假设有一个Girl(美女)实体,该实体拥有姓名.年龄两个属性,拥有显示姓名和洗澡两个方法,下面分步骤构造该实体. 1.用简单基本单体模式: var Girl1 = { name:"昭君 ...

  9. c.vim的安装和使用

    之前写了一些废话,今天写的稍微具体点. 在mac上给vim装个插件,,倒腾了半天 先要去找到c.vim.zip,自己百度下,官网就有的,我mac下下来,是直接解压的格式,而不是*.zip,也就是说不需 ...

  10. 9) 十分钟学会android--使用Fragment建立动态UI

    为了在 Android 上为用户提供动态的.多窗口的交互体验,需要将 UI 组件和 Activity 操作封装成模块进行使用,这样我们就可以在 Activity 中对这些模块进行切入切出操作.可以用  ...