在进行研究时,我遇到了此声明:
警告:使用按钮角色标记链接时要小心。 按钮预计会使用空格键触发,而链接预计将使用 Enter 键触发。 b $ b
有谁知道为什么不同的按键用于按钮/链接?
同时触发空间和 Enter ?
在阅读本文之前,作为用户,我不知道何时使用 Space 或 Enter 。
快速浏览一下Google,看看他们做了些什么。
按钮是表单元素。 如果您选择复选框元素,空格将切换复选框,而输入将提交表单。
所以为了保持一致,按钮的操作方式也是一样的。实际上,他们同时接受 enter 和 space ,没有任何区别。
阅读 ARIA的第三条规则:
例如,如果使用role = button元素必须能够获得焦点并且用户必须能够使用输入(在WIN OS上)或返回(MAC OS)和空格键来激活与元素相关联的动作。
这是出于历史原因,并非在任何官方建议中已经定义,据我所知
例如2000年的一个旧bug( https ://bugzilla.mozilla/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.
Does anyone know why a different key is used for buttons / links?
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
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.
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.
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 (bugzilla.mozilla/show_bug.cgi?id=56495) already stated that space bar was expected to work on buttons. Maybe an inheritance from Windows behavior.
更多推荐
按钮和链接键盘触发器
发布评论