Html role=form 如何帮助可访问性?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21922305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How does role=form help accessibility?
提问by user664833
I have read that the role
attribute was added to Bootstrapfor accessibility, and I would like to know how <form role="form">
helps accessibility. See http://getbootstrap.com/css/#forms-examplefor an example of this specific usage.
我已经读到该role
属性已添加到Bootstrap以实现可访问性,我想知道如何<form role="form">
帮助可访问性。有关此特定用法的示例,请参阅http://getbootstrap.com/css/#forms-example。
I searched Bootstrap's repo for "role"to no avail.
我在Bootstrap 的 repo 中搜索了“角色”,但无济于事。
My issue is that the information seems redundant. The notion that the element is a formis already expressed by the HTML tag itself (<form>
), so what does it help if we also add that the element is playing the role
of form
? It would make sense to add role="..."
if role
was going to be different than form
(I don't know what - but let's pretend); as it stands (especially without concrete reasoning / use case examples), it is puzzling at best.
我的问题是这些信息似乎是多余的。元素是表单的概念已经由 HTML 标签本身 ( <form>
)表达了,那么如果我们还添加元素正在播放 ,这role
有form
什么帮助呢?添加role="..."
ifrole
将与form
(我不知道是什么 - 但让我们假装)不同是有意义的;就目前而言(尤其是没有具体的推理/用例示例),充其量是令人费解的。
回答by Andre Polykanine
If you add a role="form"
to a form, a screen reader sees it as a region on a webpage. That means that a user can easily jump to the form with his/her region quick navigation keys (for example, in JAWS 15 you use Rfor this). And also, your user will be able to easily find where the form starts and ends because screen readers mark start and end of regions.
如果您role="form"
向表单添加,屏幕阅读器会将其视为网页上的一个区域。这意味着用户可以使用他/她的区域快速导航键轻松跳转到表单(例如,在 JAWS 15 中,您为此使用R)。而且,您的用户将能够轻松找到表单的开始和结束位置,因为屏幕阅读器会标记区域的开始和结束位置。
回答by Nelu
I'd like to point out that the article @user664833 mentioned in a commentstates that role="form"
shouldn't go on <form>
elements, but rather on a <div>
or some other element which does not semantically indicate that it contains form elements.
我想指出,评论中提到的文章@user664833指出role="form"
不应在<form>
元素上,而应在<div>
语义上未表明它包含表单元素的某个或其他元素上。
The <form>
elementis probably already handled properlyby modern screen readers.
<form>
现代屏幕阅读器可能已经正确处理了该元素。
Recommend using [
role="form"
] on a semantically neutral element such as a<div>
not on a<form>
element, as the element already has default role semantics exposed.
建议
role="form"
在语义中性元素上使用 [ ],例如在<div>
not<form>
元素上使用,因为该元素已经公开了默认角色语义。
回答by Jaccoud
In fact, the ARIA 1.1 W3C recommendation states clearly one should not change the host language semantics in section 1.4 (source):
事实上,ARIA 1.1 W3C 建议明确指出不应更改第 1.4 节(来源)中的宿主语言语义:
"It is not appropriate to create objects with style and script when the host language provides a semantic element for that type of object. While WAI-ARIA can improve the accessibility of these objects, accessibility is best provided by allowing the user agent to handle the object natively."
“当宿主语言为该类型的对象提供语义元素时,创建具有样式和脚本的对象是不合适的。虽然 WAI-ARIA 可以提高这些对象的可访问性,但最好通过允许用户代理处理这些对象来提供可访问性。本机对象。”
So, writing <form role='form'>
is not only redundant but against the recommendation.
所以,写作<form role='form'>
不仅是多余的,而且违背了建议。
回答by salmanxk
Semantically speaking, a form by default is, well, a form. However, not all accessibility applications(screen readers, etc) are designed the same and some can use elements (even the form element) with the role=form
attribute differently even if they understand that the parent form element will have the same semantic meaning with or without the role=form
attribute.
从语义上讲,默认情况下的表单是一个表单。然而,并非所有无障碍应用程序(屏幕阅读器等)的设计都是相同的,有些应用程序可以以role=form
不同的方式使用具有属性的元素(甚至表单元素),即使他们理解父表单元素在有或没有role=form
属性。