如何在打开时仅在模式弹出窗口内限制 Tab 键按下? [英] How can restrict the tab key press only within the modal popup when its open?

查看:24
本文介绍了如何在打开时仅在模式弹出窗口内限制 Tab 键按下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打开了一个模式弹出窗口.我有可访问性要求.所以添加了 ARIA 相关的标签.但是当我点击 tab 键时,持续关注到实际页面后面的页面.

I have a modal popup opened. I have accessibility requirement. So added ARIA related labels. But when i click tab key continuously focus going to the page behind the actual page.

在 html 文件中添加了 role="dialog"

但是当模式打开时,我只希望焦点在模式弹出窗口中导航.

But when modal opened i want only the focus navigate within the modal popup.

从事 Angular4, HTML5 项目.如果我们在 HTML 文件中找到解决方案会更好.我的意思是没有添加任何 javascript/jQuery 相关的东西来防止这种情况发生

推荐答案

你问的是焦点陷阱,这个演示很好地展示了它:https://focus-trap.github.io/focus-trap/

You are asking about focus trap, it's nicely demonstrated in this demo: https://focus-trap.github.io/focus-trap/

添加 role="dialog" 不会自动在该元素内提供陷阱焦点.事实上,浏览器并没有原生焦点陷阱.

Adding role="dialog" will not automatically provide trap the focus within that element. In fact, there's no native focus trap provided by browsers.

您需要选择以下选项之一:

You need to go with one of following options:

  • implement focus trap by yourself (good article on this: https://hiddedevries.nl/en/blog/2017-01-29-using-javascript-to-trap-focus-in-an-element)
  • use 3rd party solutions of focus trap, e.g. https://github.com/davidtheclark/focus-trap
  • use 3rd party solutions of modal windows, e.g. https://github.com/sweetalert2/sweetalert2 which is fully compatible with WAI-ARIA specifications and provide focus trap for you

这篇关于如何在打开时仅在模式弹出窗口内限制 Tab 键按下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆