简体   繁体   English

关闭模式的屏幕阅读器消息

[英]Screen Reader message for closing modal

We have a requirement where we are having hard time implementing.我们有一个难以实施的要求。

  • User closes modal via "X" or "Cancel" button.用户通过“X”或“取消”按钮关闭模式。 The screen reader should tell the user that pop-up is closed and focus is on [X]屏幕阅读器应告诉用户弹出窗口已关闭且焦点位于 [X]

Any suggestion around how this can be implemented?关于如何实施的任何建议?

There are many ways to solve this problem, but here's where I'd start (using JavaScript).有很多方法可以解决这个问题,但这是我要开始的地方(使用 JavaScript)。

  1. Add an aria-live region to your page HTML, and have it visually hidden.将一个 aria-live 区域添加到您的页面 HTML 中,并在视觉上隐藏它。

  2. Set an onClick event handler on your button.在您的按钮上设置一个 onClick 事件处理程序。 When the event handler is triggered, close the modal, then post a message to the aria-live region stating that the modal has closed, and finally, set focus on the respective element.当事件处理程序被触发时,关闭模式,然后向 aria-live 区域发布一条消息,说明模式已关闭,最后,将焦点设置在相应的元素上。

  3. When it comes to announcing that the focus has moved, you'll again use the aria-live region to post updates.在宣布焦点已转移时,您将再次使用 aria-live 区域发布更新。 You can either do this as part of the onClick handler (on the button), or you can do it through an onFocus handler on the element that will receive the focus.您可以作为 onClick 处理程序的一部分(在按钮上)执行此操作,也可以通过将接收焦点的元素上的 onFocus 处理程序执行此操作。 If the latter, you'll need to make sure that the previous announcements have finished before sending more text to the aria-live region.如果是后者,您需要确保之前的公告已经完成,然后再向 aria-live 区域发送更多文本。

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

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