aria-hidden

中文文档
1.2.6发布于 2025/05/19MITTypeScriptESM + CJS近 30 天下载 2.9亿

Cast aria-hidden to everything, except...

原始使用文档

aria-hidden

NPM

Hides from ARIA everything, except provided node(s).

Helps to isolate modal dialogs and focused task - the content will be not accessible using accessible tools.

Now with HTML inert support

API

Just call hideOthers with DOM-node you want to keep, and it will hide everything else. targetNode could be placed anywhere - its siblings would be hidden, but it and its parents - not.

"hidden" in terms or aria-hidden

import { hideOthers } from 'aria-hidden';

const undo = hideOthers(exceptThisDOMnode);
// everything else is "aria-hidden"

// undo changes
undo();

you also may limit the effect spread by providing top level node as a second parameter

// keep only `anotherNode` node visible in #app
// the rest of document will be untouched
hideOthers(anotherNode, document.getElementById('app'));

parentNode defaults to document.body

Inert

While aria-hidden played important role in the past and will play in the future - the main use case always was around isolating content and making elements "transparent" not only for aria, but for user interaction as well.

This is why you might consider using inertOthers

import { hideOthers, inertOthers, supportsInert } from 'aria-hidden';

// focus on element mean "hide others". Ideally disable interactions
const focusOnElement = (node) => (supportsInert() ? inertOthers(node) : hideOthers(node));

the same function as above is already contructed and exported as

import { suppressOthers } from 'aria-hidden';

suppressOthers([keepThisNode, andThis]);

⚠️ Note - inert will disable any interactions with suppressed elements ⚠️

Suppressing interactivity without inert

One can marker, the third argument to a function, to mark hidden elements. Later one can create a style matching given marker to apply pointer-events:none

[hidden-node] {
  pointer-events: none;
}
hideOthers(notThisOne, undefined /*parent = document*/, 'hidden-node');

Generally speaking the same can be achieved by addressing [aria-hidden] nodes, but not all aria-hidden nodes are expected to be non-interactive. Hence, it's better to separate concerns.

Inspiration

Based on smooth-ui modal dialogs.

See also

Size

Code is 30 lines long

Licence

MIT

版本与发布记录

aria-hidden 共发布 12 个版本,首次发布于 2018/10/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.6latest2025/05/191.5 年前
1.2.52025/05/181.5 年前
1.2.42024/03/202 年前
1.2.32023/03/043 年前
1.2.22022/11/133 年前
1.2.12022/08/234 年前

关于 aria-hidden 的常见问题

aria-hidden 是什么?

Cast aria-hidden to everything, except...

如何安装 aria-hidden?

在项目目录运行 npm install aria-hidden,或使用 pnpm add / yarn add / bun add。

aria-hidden 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

aria-hidden 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

aria-hidden 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=10。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

aria-hidden 可以商用吗?

aria-hidden 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

aria-hidden 的下载量有多少?

根据 npm 官方下载统计,aria-hidden 在 2026/10/05 – 2026/11/03 这 30 天内被下载 289,978,314 次,日均约 9,665,944 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

aria-hidden 还在维护吗?

最新版本 1.2.6 发布于 2025/05/19(1.5 年前);至今共发布 12 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/10/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。