简体   繁体   English

播报结束时切换aria-live吗?

[英]Toggle aria-live when announcement finishes?

I'm currently working on a interactive pdf reader project to make it more accessible. 我目前正在研究一个交互式pdf阅读器项目,以使其更易于访问。 I made a <p> element that's invisible on the screen and gave it the aria-live attribute. 我做了一个<p>元素,它在屏幕上是不可见的,并赋予它aria-live属性。 Whenever I want to announce something, like opening a drawer, I set the text of that <p> element. 每当我要宣布某事(例如打开抽屉)时,我都会设置该<p>元素的文本。 However, if the user wants the whole page to be announcement, which the key for Voice Over is VO + a , the <p> element is also read, but I would like to prevent that from happening. 但是,如果用户希望整个页面都是公告,而Voice Over的键是VO + a ,那么也会读取<p>元素,但是我想防止这种情况发生。

Can someone suggest if this is the proper way to announce changes? 有人可以建议这是否是宣布更改的正确方法吗? If it is then how could I prevent <p> element from being read if user wants the whole page to be read? 如果是这样,那么如果用户希望读取整个页面,该如何防止<p>元素被读取? I'm currently using the <p> element to announce if a drawer is opened/closed, or if there's a change to the font/page number etc. 我目前正在使用<p>元素来宣布是否打开/关闭了抽屉,或者字体/页码等是否发生变化。

You cannot prevent an aria-live element from being read by a screen reader reading through the whole page. 您不能阻止屏幕阅读器读取整个页面来读取aria-live元素。 You can hide it visually from the screen, but not hide it from the virtual buffer or internal representation of the screen reader so that it wouldn't be reachable and readable. 您可以从屏幕上直观地隐藏它,但不能从虚拟缓冲区或屏幕阅读器的内部表示中隐藏它,从而无法访问和读取它。

To hide the element from the screen, look at CSS classes like .visually-hidden, .sr_only, etc. present in popular frameworks. 要从屏幕上隐藏元素,请查看流行框架中存在的CSS类,如.visually-hidden,.sr_only等。 This is a common way of showing something to screen reader users while hiding it for regular screen users. 这是向屏幕阅读器用户显示某些内容,而对常规屏幕用户隐藏该内容的一种常用方法。

To hide the element from screen reader representation (but not necessarily the screen), you can use aria-hidden. 要从屏幕阅读器表示中隐藏元素(但不一定是屏幕),可以使用aria-hidden。 But then aria-live become inoperant as well. 但是随后,咏叹调生活也变得无效了。

You may also think to use display:none or visibility:hidden to hide the element from both the scren reader and the visual screen. 您可能还会认为使用display:none或visible:hidden隐藏对scren阅读器和可视屏幕的元素。 Other tricks of the same kind like font:0, width/height:0, opacity:0, clip:0, etc. have the same problem and they don't necessarily effectively hide the element everywhere. 其他相同的技巧,例如font:0,width / height:0,opacity:0,clip:0等也有相同的问题,它们不一定有效地将元素隐藏在各处。 In that case though, the behavior isn't consist. 但是,在那种情况下,行为就不存在。 ARia-live will stay operant as normal in Some screen readers + browser combinations depending on the exact trick used, while it will stop working with others, most notably VoiceOver on Safari Mac and iOS. 根据使用的确切技巧,在某些屏幕阅读器和浏览器组合中,ARia-live将保持正常运行,而将停止与其他屏幕阅读器一起工作,尤其是在Safari Mac和iOS上的VoiceOver。

A small trick consists of removing the element from the DOM or making it blank a short while after it has been shown or set, so that a scren reader going through the page wouldn't find it afterwards. 一个小技巧是从DOM中删除该元素,或在显示或设置之后不久将其空白,以免一晃一晃的读者之后便找不到该页面。 However, you must also be careful with this. 但是,您还必须注意这一点。 I have already observed in certain cases that it makes the screen reader to immediately cut of the announcement if the element was deleted too early (while the announcement was still being spoken). 在某些情况下,我已经观察到,如果元素删除得太早(在仍在播报公告的同时),它会使屏幕阅读器立即删除该公告。 And, of course, you have no way of knowing if the screen reader already finished to read a message, if it is currently reading it, or if it hasn't yet read it. 而且,当然,您无法知道屏幕阅读器是否已经完成阅读消息,当前是否正在阅读消息或尚未阅读消息。 If you do this, take your time and leave the element visible 5, 10 or more seconds to make sure the message is read entirely. 如果这样做,请花点时间让元素可见5秒钟,10秒钟或更长时间,以确保完全读取该消息。

So, in conclusion, you have no real good way to keep your aria-live element working while preventing it from being reached by screen readers' normal ways of reading through a page. 因此,总而言之,您没有一种真正好的方法来保持aria-live元素正常工作,同时又无法防止屏幕阅读器通过正常的页面阅读方式访问它。

As @quentinc already explained the differences between visually hidden and screen reader hidden elements, you can't have an element be available to a screen reader but prevent it from a "read all" command. 正如@quentinc已经解释了视觉隐藏元素和屏幕阅读器隐藏元素之间的区别一样,您不能让屏幕阅读器可以使用该元素,但是要阻止它使用“全部读取”命令。

Using aria-live is very handy in many situations but without more details about your specific situation, it's hard to suggest alternative recommendations. 在许多情况下使用aria-live非常方便,但是由于没有关于您的具体情况的更多详细信息,因此很难提出其他建议。 But, since you did mention "drawer open", to me that sounds like something that can expand/collapse. 但是,由于您确实提到过“抽屉打开”,对我来说,这听起来像是可以扩展/折叠的东西。 If so, then you should check out aria-expanded . 如果是这样,那么您应该检查出aria-expanded You can change the value of that attribute from false to true to indicate to a screen reader that something expanded. 您可以将该属性的值从false更改为true以向屏幕阅读器指示已扩展内容。 A drawer opening would be considered expanded. 抽屉开口被认为是扩大的。 The screen reader will take care of announcing the change so you wouldn't need aria-live . 屏幕阅读器将负责宣布更改,因此您不需要aria-live

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

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