[AngularJS] Accessible Button Events

本文讲解了如何使用HTML和JavaScript改进按钮的可访问性,包括正确使用'button'元素及如何为非标准元素添加必要的属性如'role'、'tabindex'和'aria-label',并介绍了在AngularJS中处理键盘事件的方法。

Often buttons need to be handled by JavaScript, and if done improperly it can lead to accessibility issues. In this lesson you will improve a major news organization's global header with some basic HTML and JavaScript.

 

Normal you should use native 'button' to make a button instead of use other html element to make a button, then you can access the button thought the keyboard.

If you use a 'div', then what you should do to make it accessible to the user by keyborad, you should add 'role', 'tabindex' & 'aria-label' to it:

<button aria-label="Help">
    <i class="icon icon-help"></i>
</button>

<div class="button" role="button" tabindex="0" aria-label="Menu">
    <i class="icon icon-menu"></i>
</div>

 

If you use AngularJS,and you want press 'Enter' to get the handle event, you should add 'ng-keydown' for it:

<button aria-label="Help" ng-click="doStuff()">
    <i class="icon icon-help"></i>
</button>

<div class="button" role="button" tabindex="0" aria-label="Menu" ng-click="doStuff()" ng-keydown="doStuff()">
    <i class="icon icon-menu"></i>
</div>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值