ax 可访问性规则所有页面内容都必须包含在地标中,声明所有顶部 html 元素都应该是地标元素,例如
<html lang="en">
<head>
<title>Hello</title>
</head>
<body>
<header>This is the header</header>
<nav>This is the nav</nav>
<main>This is the main</main>
<footer>This is the footer</footer>
</body>
</html>
但是 React 项目需要在 body 下方有一个根元素(需要避免与其他脚本发生冲突
<html lang="en">
<head>
<title>Hello</title>
</head>
<body>
<div id="root">
<header>This is the header</header>
<nav>This is the nav</nav>
<main>This is the main</main>
<footer>This is the footer</footer>
</div>
</body>
</html>
我试图设置aria-hidden="true"
为我的 div 让屏幕阅读器忽略它
<div id="root" aria-hidden="true">
但这又引发了另一个问题:aria-hidden 元素不包含可聚焦元素
我找不到其他人讨论这个问题,这让我怀疑它是否相关。有没有一种干净的方法可以让一个具有里程碑意义的顶级元素的反应应用程序?还是我应该忽略这个特定的斧头规则?