简体   繁体   English

当焦点从 aria-live 区域 div 获得输入字段时,如何防止屏幕阅读器停止阅读内容?

[英]How can I prevent the screen reader from stopping to read the content when the focus is gained to the input field from an aria-live region div?

I have a chatbot interface where a live region div with an aria-live attribute is used to display new messages.我有一个聊天机器人界面,其中带有 aria-live 属性的实时区域 div 用于显示新消息。 The live region updates correctly and the screen reader starts to read the content, but it stops reading in the middle when the focus is gained to the input field.实时区域更新正确,屏幕阅读器开始阅读内容,但当焦点进入输入字段时,它会在中间停止阅读。 This is causing confusion for screen reader users and makes it difficult for them to understand the new messages.这会导致屏幕阅读器用户感到困惑,并使他们难以理解新消息。

I am looking for a solution to ensure that the screen reader continues to read the new messages until they are finished and that the focus management is correct when the live region updates.我正在寻找一种解决方案,以确保屏幕阅读器继续阅读新消息直到它们完成,并且在实时区域更新时焦点管理是正确的。 Is there any solution to ensure that the live region updates are announced by the screen reader in a timely manner and the focus is managed correctly?是否有任何解决方案可以确保屏幕阅读器及时宣布实时区域更新并正确管理焦点?

Screen Reader: NVDA + Firefox屏幕阅读器: NVDA + Firefox

Unfortunately, you can neither ensure that the screen reader will read new messages entirely, neither be certain that new incoming messages won't interrupt older ones.不幸的是,您既不能确保屏幕阅读器会完整地阅读新消息,也不能确定新的传入消息不会打断旧消息。 Be it because of a notification of any kind, because the focus changes, or whatever else.无论是因为任何类型的通知,因为焦点改变,还是其他原因。

Politeness level of aria-live aria-live 的礼貌级别

Remember by the way that aria-live=assertive normally means always interrupt what's currently being spoken, so it's rarely a good idea to do so.顺便记住aria-live=assertive通常意味着总是打断当前正在说的话,所以这样做很少是个好主意。 It's much better to keep aria-live=polite .最好保留aria-live=polite

As my own observations show , you can help a little screen readers to be more stable, avoiding many unwanted interrupts/skips/repeats, though, by being very careful on what you do exactly in the live region.正如我自己的观察所显示的那样,您可以帮助小屏幕阅读器更加稳定,避免许多不必要的中断/跳过/重复,不过,要非常小心您在实时区域中所做的事情。

Change of focus焦点改变

However and in particular, live-region messages are interrupted when the focus changes.但是,特别是当焦点改变时,实时区域消息会被中断。 You can't prevent the screen reader from immediately announcing the focused element when the focus changes.您无法阻止屏幕阅读器在焦点更改时立即通告焦点元素。

In principle, this is much more important to have this information in a timely manner, rather than any message coming from a live region.原则上,及时获得此信息比来自实时区域的任何消息更为重要。 Reactiveness to tab, arrow keys and other important keys is crucial for a good user experience, as well as always exactly knowing where you are and what you can/should do.对选项卡、箭头键和其他重要键的反应对于良好的用户体验至关重要,同时始终准确地知道您在哪里以及您可以/应该做什么。

So, it's perfectly normal that focus change takes the priority almost above everything and that you can't influence on it.因此,焦点更改几乎高于一切并且您无法影响它是完全正常的。

The best way to avoid focus changes taking the priority over everything else is in fact very simple: don't move the focus unexpectedly unless you have a good reason.避免焦点改变优先于其他一切的最佳方法实际上非常简单:除非有充分的理由,否则不要意外地移动焦点

In your chatbot example, there is no reason to move the focus upon arrival of a new message.在您的聊天机器人示例中,没有理由在新消息到达时移动焦点。 If the focus was in the text box when the user pressed enter to submit a question, the focus should stay there as long as the user don't explicitly leave it by him/herself.如果当用户按下 enter 键提交问题时焦点位于文本框中,只要用户没有明确将焦点留在该处,焦点就应该保留在那里。

If the focus stays in the text box, then the screen reader user can just have the response automatically read via aria-live, and can directly type in a new message when ready.如果焦点停留在文本框中,那么屏幕阅读器用户可以通过 aria-live 自动阅读回复,并可以在准备好后直接输入新消息。 The conversation can go quick and fluent.谈话可以 go 快速流利。

Avoid DOM changes close to focus避免靠近焦点的 DOM 更改

Avoid making changes to the DOM enclosing or nearby the text box.避免更改文本框周围或附近的 DOM。 A change in the DOM, especially when using frameworks like angular or react, basically means removing it and adding it again. DOM 的变化,尤其是在使用像 angular 或 react 这样的框架时,基本上意味着删除它并再次添加它。 At worst the focus can be completely lost, at best it still creates a focus jump out and in again that will generate an unwanted interruption.在最坏的情况下,焦点可能会完全丢失,充其量它仍然会造成焦点跳出并再次跳入,从而产生不必要的中断。

The best is to test what you can or can't change without triggering a DOM rebuild, and adjust your HTML structure in consequence.最好的方法是测试在不触发 DOM 重建的情况下可以更改或不能更改的内容,并因此调整 HTML 结构。

Leave users in control to read messages让用户控制阅读消息

Don't forget that screen reader user already can quit the textbox and read the missed messages on their own terms.不要忘记屏幕阅读器用户已经可以退出文本框并按照自己的方式阅读错过的消息。 A screen reader already has shortcuts to read backwards (up arrow in NVDA).屏幕阅读器已经有了向后阅读的快捷方式(NVDA 中的向上箭头)。 This will just not work inside the textbox.这在文本框内不起作用。

Still, it would seem a best practice to allow focussing single chat messages.尽管如此,允许聚焦单个聊天消息似乎是最佳实践。 This is especially true if there are actions you can take on these messages, like replying, editing or deleting.如果您可以对这些消息执行一些操作,例如回复、编辑或删除,则尤其如此。

Microsoft Teams simply allows for tab navigation between chat messages , but it's a dedicated chat application. Microsoft Teams 只允许在聊天消息之间进行选项卡导航,但它是一个专用的聊天应用程序。

If the conversation is embedded in a larger page, it should be treated as a composite widget , which only has one focus stop, but allows focussing the contained controls via vertical arrow keys:如果对话嵌入在一个更大的页面中,它应该被视为一个复合小部件,它只有一个焦点停止,但允许通过垂直箭头键聚焦包含的控件:

Authors SHOULD ensure that a composite widget exists as a single navigation stop within the larger navigation system of the web page.作者应该确保复合小部件作为 web 页面的较大导航系统中的单个导航站存在。 Once the composite widget has focus, authors SHOULD provide a separate navigation mechanism for users to navigate to elements that are descendants or owned children of the composite element.一旦复合小部件获得焦点,作者应该为用户提供一个单独的导航机制,以导航到作为复合元素的后代或拥有的子元素的元素。

Livechat seems to use arrow keys to navigate between messages Livechat 似乎使用箭头键在消息之间导航

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

相关问题 屏幕阅读器无法读取 Firefox 中的 Aria-Live - Aria-Live in Firefox not read by screen reader Aria-live 内容被 Mac 读取两次 - Chrome - VoiceOver - Aria-live content read twice by Mac - Chrome - VoiceOver 当 aria-live 区域第一次更新时,aria- describeby 会重复 - aria-describedby repeats when aria-live region updates for the first time 使用 aria-live 向 vue.js 中的屏幕阅读器宣布信息 - Announcing information to a screen reader in vue.js using aria-live 设置aria-live以读取更新,然后重点读取DOM元素 - Set aria-live to read updates before reading out the DOM element in focus 在 chrome 上删除元素时,Aria-live 区域不会读取更新 - Aria-live region is not reading out updates when an element is removed on chrome 播报结束时切换aria-live吗? - Toggle aria-live when announcement finishes? 当输入失去焦点时,如何防止屏幕滚动到 x:0, y:0? - How do I prevent the screen from scrolling to x:0, y:0 when an input loses focus? 如何让屏幕阅读器 NVDA 在 listitem (ARIA) 上按下 ENTER 键? - How can I make screen reader NVDA reads ENTER key when press it on listitem (ARIA)? 如何防止屏幕阅读器焦点(不是指键盘焦点)离开预定义区域(例如,模态) - How to prevent screen reader focus (not referring to keyboard focus) from leaving predefined area (e.g., modal)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM