简体   繁体   English

旋转木马的 WAI-ARIA 角色(又名滑块、幻灯片、画廊)

[英]WAI-ARIA Roles for Carousels (a.k.a. sliders, slideshows, galleries)

What WAI-ARIA roles should be used for carousels, like the one below?轮播应该使用哪些WAI-ARIA 角色,如下所示?

USA.gov 轮播示例

Notes:笔记:

  • I'm familiar with the slider role, but this refers to a different type of widget.我熟悉滑块角色,但这指的是不同类型的小部件。
  • The example is from USA.gov and the only aria role I see in use that's related to the carousel is aria-live on the individual slides.该示例来自USA.gov ,我在使用中看到的与轮播相关的唯一 aria 角色是各个幻灯片上的aria-live

as you correctly say, role=slider is not right for a carousel.正如您所说的那样, role=slider不适合轮播。 The one that you should use is role=listbox您应该使用的是role=listbox

quoting from MDN (see link below):引用自 MDN(见下面的链接):

The listbox role is used to identify an element that creates a list from which a user may select one or more items which are static and, unlike HTML elements, may contain images. listbox 角色用于标识创建列表的元素,用户可以从中选择一个或多个静态项目,并且与 HTML 元素不同,它可能包含图像。

see https://developer.mozilla.org/en-US/docs/Accessibility/ARIA/ARIA_Techniques/Using_the_listbox_role for additional information on other ARIA roles you should use, such as role=option for each entry in the listbox.有关您应该使用的其他 ARIA 角色的更多信息,请参阅https://developer.mozilla.org/en-US/docs/Accessibility/ARIA/ARIA_Techniques/Using_the_listbox_role ,例如列表框中每个条目的role=option

You could also have a look at this YUI plugin (YUI 2 is deprecated but the documentation is still valid for the purpose of your question) http://yui.github.io/yui2/docs/yui_2.9.0_full/examples/carousel/carousel-ariaplugin.html您还可以查看此 YUI 插件(不推荐使用 YUI 2,但文档对于您的问题仍然有效) http://yui.github.io/yui2/docs/yui_2.9.0_full/examples/carousel /carousel-ariaplugin.html

that adds aria roles to an existing carousel via javascript.通过 javascript 将 aria 角色添加到现有轮播中。 I'm not suggesting to use it, but you can certainly infer what it does and replicate it in your markup as needed.我不建议使用它,但您当然可以推断它的作用并根据需要在标记中复制它。

Here's an example of an accessible carousel using jQuery UI: http://hanshillen.github.io/jqtest/#goto_carousel下面是一个使用 jQuery UI 的可访问轮播示例: http : //hanshillen.github.io/jqtest/#goto_carousel

The control bar is a list of images, marked up with <ul role="listbox"> .控制栏是一个图像列表,用<ul role="listbox">标记。 Each <li> has role="option" , tabindex="-1" , and aria-selected="false" .每个<li>都有role="option"tabindex="-1"aria-selected="false"

The two arrows are <button> elements with title="previous" and title="next" , and when a button is pressed the previous or next list item is selected, in which case that list item's attributes change to aria-selected="true" and tabindex="0" .两个箭头是带有title="previous"title="next" <button>元素,当按下按钮时,将选择上一个或下一个列表项,在这种情况下,列表项的属性更改为aria-selected="true"tabindex="0" The latter means the user can tab directly to the current selected image, which of course has suitable alt text.后者意味着用户可以直接跳转到当前选择的图像,当然还有合适的替代文字。

Another option not included in this example might be to add role="alert" to the viewer div, so when the content of that div changes the new alt text is automatically read.此示例中未包含的另一个选项可能是将role="alert"添加到查看器 div,因此当该 div 的内容更改时,会自动读取新的替代文本。 That way users don't have to press tab to see what the image is, then shift + tab to go back to the button.这样用户就不必按Tab键查看图像,然后按shift + Tab键返回按钮。

I have seen many examples using role="listbox" , but this feels incorrect to me.我看过很多使用role="listbox"例子,但这对我来说是不正确的。 A listbox is a form control, wanting to get a selection from a user.列表框是一个表单控件,希望从用户那里获得选择。 If the purpose of your carousel is to have a user select an option, then use listbox , but most people do not use carousel components in this manner.如果轮播的目的是让用户选择一个选项,那么使用listbox ,但大多数人不会以这种方式使用轮播组件。 A better role would be a tablist .更好的角色是tablist Tablists are used to represent data (as opposed to capturing an option).表格列表用于表示数据(与捕获选项相反)。 Carousel represent data.轮播代表数据。 The links to display a certain image would have the role of tab and each image with it's corresponding data such as its caption would get a role of tabpanel .显示特定图像的链接将具有tab的作用,每个图像及其相应的数据(例如其标题)将具有tabpanel的作用。

See http://www.w3.org/TR/2010/WD-wai-aria-practices-20100916/#tabpanelhttp://www.w3.org/TR/2010/WD-wai-aria-practices-20100916/#tabpanel

From the official W3 tutorials :来自官方W3 教程

To group the carousel in a way that is perceivable for assistive technologies, the role attribute with a value of region can be used.要以辅助技术可感知的方式对轮播进行分组,可以使用值为regionrole属性。 To identify the region, the aria-label attribute can be used, as show in the example below:要识别区域,可以使用aria-label属性,如下例所示:

 <div class="carousel" role="region" aria-label="Recent news"> … </div>

So you should use role="region"所以你应该使用role="region"

tl;dr: tl;博士:

role="marquee"


A carousel is not a listbox .轮播不是列表框

From the listbox description从列表框描述

A widget that allows the user to select one or more items from a list of choices.允许用户从选项列表中选择一个或多个项目的小部件。

The listbox role is a subclass of select . listbox 角色是select的子类。 While I'm sure there are exceptions, carousels are generally not used as form elements where users "select one or more items", and should not use a role that would otherwise treat them as such.虽然我确定有例外,但轮播通常不会用作用户“选择一个或多个项目”的表单元素,并且不应使用其他方式将它们视为此类的角色。

A better role for a carousel is tablist so long as bullets or numbering for the carousel slides are provided and toggle depending on which one is active:轮播的一个更好的角色是tablist ,只要提供轮播幻灯片的项目符号或编号,并根据哪个活动进行切换:

A list of tab elements, which are references to tabpanel elements. tab 元素的列表,它们是对 tabpanel 元素的引用。

An all around-better role for carousels is marquee , as there is no dependency on showing "tabs" as bullets or numbers to access different slides:轮播的一个更好的角色是marquee ,因为不依赖于将“标签”显示为项目符号或数字来访问不同的幻灯片:

A type of live region where non-essential information changes frequently.一种非必要信息频繁变化的实时区域。

Now that other answers already can't agree on role "listbox", "region" or "marquee", another one pops up: role "group", in combination with role description "carousel".既然其他答案已经不能就角色“列表框”、“区域”或“选框”达成一致,那么会弹出另一个答案:角色“组”,结合角色描​​述“轮播”。

From the, very official, WAI-ARIA Authoring Practices 1.2 (emphasis mine):来自非常官方的WAI-ARIA Authoring Practices 1.2 (重点是我的):

  • A carousel container element [...] has either role region or role group .轮播容器元素 [...] 具有角色区域或角色组 The most appropriate role for the carousel container depends on the information architecture of the page.轮播容器最合适的角色取决于页面的信息架构。 [...] [...]

  • The carousel container has the aria-roledescription property set to carousel . carousel 容器的aria-roledescription 属性设置为 carousel

A11y is hard. A11y 很难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM