按钮和链接键盘触发器 [英] Buttons and links keyboard triggers

查看:232
本文介绍了按钮和链接键盘触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在进行研究时,我遇到了此声明


警告:使用按钮角色标记链接时要小心。
按钮预计会使用空格键触发,而链接
预计将使用 Enter 键触发。 b $ b




  1. 有谁知道为什么不同的按键用于按钮/链接?


  2. 同时触发空间 Enter


在阅读本文之前,作为用户,我不知道何时使用 Space Enter






快速浏览一下Google,看看他们做了些什么。


  • For 链接 空格向下滚动和 Enter 触发器

  • > 空格和 Enter 触发器


解决方案


  1. 按钮是表单元素。 如果您选择复选框元素,空格将切换复选框,而输入将提交表单。

    所以为了保持一致,按钮的操作方式也是一样的。实际上,他们同时接受 enter space ,没有任何区别。

  2. 不仅可以,但你必须



    阅读 ARIA的第三条规则


    例如,如果使用role = button元素必须能够获得焦点并且用户必须能够使用输入(在WIN OS上)或返回(MAC OS)和空格键来激活与元素相关联的动作。



  3. 这是出于历史原因,并非在任何官方建议中已经定义,据我所知



    例如2000年的一个旧bug( https ://bugzilla.mozilla.org/show_bug.cgi?id = 56495 )已经指出,空格键预计在按钮上工作。也许是Windows行为的继承。



While doing research I came across this statement:

Warning: Be careful when marking up links with the button role. Buttons are expected to be triggered using the Space key, while links are expected to be triggered using the Enter key.

  1. Does anyone know why a different key is used for buttons / links?

  2. Is it ok to trigger using both Space and Enter?

Before reading this I, as a user, would have had no idea when to use Space or Enter.


Had a quick look at Google to see what they do.

  • For links Space scrolls down and Enter triggers
  • For buttons both Space and Enter trigger

解决方案

  1. Buttons are form elements.

    If you select a checkbox element, space will toggle the checkbox while enter will submit the form.

    So to be coherent, buttons act the same way. In practice, they accept both enter and space without any difference.

  2. It is not only ok but you have to

    Read inside the Third rule of ARIA:

    For example, if using role=button the element must be able to receive focus and a user must be able to activate the action associated with the element using both the enter (on WIN OS) or return (MAC OS) and the space key.

  3. This is for historical reason, not that it has been defined in any official recommendation, as far as I know

    For instance an old bug from 2000 (https://bugzilla.mozilla.org/show_bug.cgi?id=56495) already stated that space bar was expected to work on buttons. Maybe an inheritance from Windows behavior.

这篇关于按钮和链接键盘触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆