ios - 尽管 <label/> 中存在 aria-hidden 属性,但旁白仍会读取伪元素

标签 ios accessibility wai-aria voiceover screen-readers

我通过使用 :before css 规则在标签元素上添加伪元素来创建自定义单选/复选框图标。我已将 aria-hidden 添加到 label 元素,但 iOS 上的 VO 仍在读取伪元素。

我知道,如果元素提供附加上下文,某些屏幕阅读器将忽略 aria-hidden 属性(标签元素就是这种情况,因为它们提供有关连接的输入元素的附加信息)。为了解决这个问题,我添加了一个 aria-label 属性,但同样,iOS 上的 VO 会忽略它。这似乎解决了其他屏幕阅读器、浏览器和设备组合(例如“讲述人”和 IE/Edge)的相同问题。

我还尝试向标签添加子 span 或 i 元素,并添加 :before css 规则和 aria-hidden 属性,但 iOS 上的 VO 仍在读取伪元素。

有人对让屏幕阅读器阅读正确的内容有什么建议吗?

我的基本方法如下(注意:在 jsfiddle 中不起作用,因为我没有加载我的字体)。
您还可以在此处查看第一个示例: http://uatwww.surveygizmo.com/s3/4102902/Basic-Radio

<input type="radio" id="radio1" value="1" name="example" />
<label for="radio1" class="custom-icon" aria-hidden="true" aria-label="example 1">Example 1</label>

<input type="radio" id="radio2" value="2" name="example" />
<label for="radio2">
    <span class="custom-icon" aria-hidden="true" aria-label="example 2"></span>
    Example 2
</label>

<input type="radio" id="radio3" value="3" name="example" />
<label for="radio3">
    <i class="custom-icon" aria-hidden="true" aria-label="example 3"></i>
    Example 3
</label>

<style>
input[type=radio] {
    opacity: 0;
    position: absolute;
    border: 0;
    height: 0;
    margin: 0;
    overflow: hidden;
    padding: 0;
}
input[type=radio] + .custom-icon:before,
input[type=radio] + label .custom-icon:before {
    content: "\26aa";
}
input[type=radio]:checked + .custom-icon:before,
input[type=radio]:checked + label .custom-icon:before {
    content: "\26ab";
}
</style>

最佳答案

我认为问题在于您向浏览器和屏幕阅读器发出了令人困惑的指令。您有一个不可见的输入,其中附加了 CSS 内容,然后该输入与一个 aria-hidden 但也有 aria-label 的标签相关联。在不同的浏览器/屏幕阅读器组合中,您肯定会得到不一致的标记解释。

我用过Heydon Pickering’s custom control method成功地在一堆网站上运行,没有任何问题。这似乎是您目标的一个更简单的版本。它可以轻松地对除屏幕阅读器软件之外的所有人隐藏输入,将 CSS 内容放在跨度上而不是标签或输入上。他不使用任何 ARIA,但如果最新版本的 VoiceOver 公布了 CSS 内容,您可以将 aria-hidden 放在跨度上,让屏幕阅读器将标签和输入视为正常。

关于ios - 尽管 <label/> 中存在 aria-hidden 属性,但旁白仍会读取伪元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48103260/

相关文章:

html - aria-labelledby 引用 DOM 中不存在的 id(尚未)

javascript - 带箭头按钮的 aria 角色选项卡

ios - 如何停止 CATransform3DMakeScale 动画缩放变化?

css - 扩展的可点击区域在 Firefox 中不起作用

html - 使用显示 :table-row 在 HTML 表格中自动换行

html - 辅助功能:在页面加载时强制阅读跨度文本的方法是什么

javascript 添加 aria 属性

ios - NSMutableData 到 NSString

ios - 如何在 swift3 项目中使用 Objective C View Controller

ios - 移除移动的 GMSPolyline 线段