简体   繁体   English

HTML5辅助功能:如何指示在网格布局和列表布局之间切换?

[英]HTML5 Accessibility: How to indicate switching between grid and list layout?

I want to create buttons to switch between grid and list layout for displaying table of images: 我想创建按钮以在网格和列表布局之间切换以显示图像表:

<div>
    <span>Layout:</span>
    <button ng-click="$ctrl.switchToList()">
        <span class="fa fa-list" aria-hidden="true"></span>
        <span class="sr-only">Set list layout</span>
    </button>
    <button ng-click="$ctrl.switchToGrid()">
        <span class="fa fa-th" aria-hidden="true"></span>
        <span class="sr-only">Set grid layout</span>
    </button>
</div>

And if list is chosen layout looks like regular table ( <tr> and image data in separated <td> s, no thumbnail), when grid is chosen it looks like grid of thumbnail. 并且,如果选择列表,则布局看起来像常规表格( <tr> ,图像数据放在单独的<td> ,没有缩略图),当选择网格时,它看起来就像缩略图的网格。 But I don't know how to label to screen readers / search engines that Layout label describes this 2 possibilities. 但是我不知道如何在屏幕阅读器/搜索引擎中标记Layout标签描述了这两种可能性。 It's easy if it comes to radios/checkboxes cause then fieldset / legend approach can be used, but there is no form. 如果涉及到收音机/复选框,则很容易,则可以使用字段集/图例方法 ,但是没有任何形式。 It looks like there is 2 possible solutions: aria-describedby or aria-labelledby . 看来有两种可能的解决方案: aria- describebyaria-labeledby But they quite similar and IMO they do not fit in 100% to my problem - cause I need something like fieldset / legend to indicate possible values rather than aditional description, I think. 但是它们与IMO非常相似,因此不能完全满足我的问题-因为我认为我需要诸如fieldset / legend类的东西来表示可能的值,而不是附加说明。 Is there something which can help me, something like fieldset / legend but not for forms? 有什么可以帮助我的东西,例如fieldset / legend但不适用于表单吗? Thank you in advance for every answer. 预先感谢您的每一个回答。

You could use fieldset / legend without a form . 您可以使用没有form fieldset / legend

But do you need to do anything in the first place? 但是您首先需要做任何事情吗? The button elements already have descriptive labels (their content), and can stand on their own. button元素已经具有描述性标签(它们的内容),并且可以独立使用。 An additional label like "Layout" doesn't really add anything, as the buttons already make clear that they set the layout. 像“布局”这样的附加标签实际上并没有添加任何内容,因为按钮已经清楚地表明它们已设置布局。

You could consider to use the menu role ("A type of widget that offers a list of choices to the user."), and give each button the menuitem role : 您可以考虑使用menu角色 (“一种为用户提供选择列表的小部件类型。”),并为每个按钮提供menuitem角色

An option in a group of choices contained by a menu or menubar . menumenubar包含的一组选项中的一个选项。

Note that you can't use menu on a fieldset element. 请注意,您不能在fieldset元素上使用menu You could use something like this: 您可以使用如下形式:

<div role="menu">
  <button type="button" role="menuitem">Set grid layout</button>
  <button type="button" role="menuitem" disabled>Set list layout</button>
</div>

(Note that I added type="button" ; otherwise the buttons are considered to be submit buttons.) (请注意,我添加了type="button" ;否则,这些按钮被视为提交按钮。)

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

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