[英]Star rating component - What are the correct accessibility and semantics to be used
我有一个星级评分组件,目前有以下语义。 SVG只是明星。
<div role='img' aria-label="6 out of 6 ratings">
<svg role="presentation"></svg>
<svg role="presentation"></svg>
<svg role="presentation"></svg>
<svg role="presentation"></svg>
<svg role="presentation"></svg>
<svg role="presentation"></svg>
</div>
我使用了role='img'
咏叹调角色,因为我希望理想将此图像视为一个图像。 然后,我已经使用了role='presentation'
的咏叹调角色SVG
,因为我觉得SVG的单独提供没有多余的信息,因此要删除的语义到SVG和它的孩子。 我在这里阅读了演讲角色 。
我读了一篇关于SVG可访问性的文章 ,他们采用略有不同的方法。 他们给出的例子如下:
<body>
...
<svg xmlns=http://www.w3.org/2000/svg role="img" aria-labelledby="title desc">
<title id="title">Circle</title>
<desc id="desc">Large red circle with a black border</desc>
<circle role="presentation" cy="60" r="55" stroke="black" stroke-width="2"
fill="red" />
</svg>
…
</body>
role='img
。 我相信这不适用于我的情况,我会更好地在我的SVG上保持role='presentation'
吗? title
和desc
。 我相信作为单星SVG,它不会给用户带来任何额外的好处吗? 还将鼠标悬停在SVG上会显示我不想要的标题(和desc?)。 回到我的例子,我现在如何拥有它:
看一下semantic-ui的例子,他们从我所看到的角色中没有咏叹调的角色。
用于img
角色的MDN Web文档具有指向星级评分角色=“img”示例的链接
他们使用aria-hidden
而不是role="presentation"
根据规范, img
角色应该已经让它的孩子呈现出来
我想补充说,可访问意味着不仅仅是屏幕阅读器的可访问性。 例如, MDN示例中的“3个黑色星星,2个白色星星”是人们可能无法理解的东西(例如,人们自然地从右向左阅读)。
“奶奶:亲爱的,拥有5颗白色星星或5颗黑色星星会更好吗?”
我会说在评级旁边添加“Note:3/5”可能是一个很好的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.