Neova高级 SEO 平台

对话框没有可访问名称

在 Neova 中 直接在抓取过程中运行,无需任何设置。

规则最近审核:2026年10月17日 · 指南更新:2026年7月7日

无障碍最佳实践,不是 WCAG 的要求。没有名称的对话框打开时,使用屏幕阅读器的用户得不到任何上下文。对话框内的文本不算名称。

您可以做什么

让 aria-labelledby 指向对话框的标题,或添加 aria-label。

Neova 为何标记

  • 没有名称的对话框打开时没有任何上下文,屏幕阅读器用户不知道它的用途。
  • 对话框内的文字不会自动成为它的名称,所以需要 aria-labelledby 或 aria-label。
  • 这是 ARIA Authoring Practices 中的最佳实践,本身不是 WCAG 要求。

来源

完整指南

这一部分目前只有英文版。

Aria dialog and alertdialog must have an accessible name: how to fix it
TL;DR

Any element with role="dialog" or role="alertdialog" needs a name, or a screen reader announces "dialog" and nothing else. Point aria-labelledby at the heading and the modal introduces itself.

This check flags a modal container carrying role="dialog" or role="alertdialog" that has no accessible name. When focus lands inside a nameless dialog, assistive tech says "dialog" with no context, so the user has no idea whether they are in a cookie prompt, a delete confirmation, or a checkout step. Dialogs are also where conversions happen, so a modal a screen reader user cannot parse is a straight path to a bounced session and a lost sign-up.

Why the Name Matters More in a Dialog Than Almost Anywhere Else

A dialog is a context switch. The moment it opens, a screen reader user is torn out of the page they were reading and dropped somewhere new, usually with focus moved into the modal. In that instant the accessible name is the only orientation they get. On a normal page you can explore headings and landmarks to figure out where you are, but a modal is meant to be a small, self-contained task, and users expect it to announce itself the way a well-labeled door announces the room behind it. Miss the name and you have effectively teleported someone into an unmarked room and asked them to make a decision. For an alertdialog the stakes climb higher, because these are reserved for urgent, often destructive choices, and the whole point is that the user hears the message before they act. A nameless confirmation dialog is how a keyboard-and-audio user deletes something they never meant to touch.

A Real Failure, and the Fix

A common React or vanilla modal ships the role but forgets the name entirely:

<div role="dialog" aria-modal="true">
  <h2>Delete this project?</h2>
  <p>This action cannot be undone.</p>
  <button>Cancel</button> <button>Delete</button>
</div>

The heading already says exactly what this dialog is, so reuse it. Give the <h2> an id and reference it with aria-labelledby:

<div role="dialog" aria-modal="true" aria-labelledby="dlg-title">
  <h2 id="dlg-title">Delete this project?</h2>
  <p>This action cannot be undone.</p>
  <button>Cancel</button> <button>Delete</button>
</div>

Now, on open, the screen reader announces "Delete this project?, dialog" and the user knows precisely where they are.

Dialog vs Alertdialog, and How to Name Each

Role Use It For Preferred Name Source Also Needs
dialog Forms, pickers, general modals aria-labelledby → heading Focus trap, aria-modal
alertdialog Urgent confirmations, errors aria-labelledby → heading aria-describedby → body text
Either, no visible title Icon-only or compact prompts aria-label="…" Concise, purpose-first text

How to Detect It

  1. axe DevTools: open the modal first so it is in the DOM, then run the scan; "ARIA dialog and alertdialog nodes should have an accessible name" pinpoints the offending container.
  2. Lighthouse: run the Accessibility category with the dialog open and read the "ARIA" failures; a nameless dialog surfaces there.
  3. WAVE: trigger the modal, run WAVE, and inspect the ARIA panel for a dialog node with no associated name.
  4. Screen reader spot check: open the modal with VoiceOver or NVDA; if it announces "dialog" with no title, the name is missing.

How to Fix It

Prefer aria-labelledby pointing at the visible heading, because the name then always matches what sighted users read. Only fall back to aria-label when there is genuinely no on-screen title. For an alertdialog, add aria-describedby targeting the body copy so the warning message is announced along with the name. Make sure the id you reference actually exists and is unique, and that the dialog receives focus on open. Buttons inside the dialog have their own naming requirement, covered in buttons must have discernible text, and the same accessible-name concept extends to widgets like ARIA tooltip must have an accessible name.

A few implementation details save you from re-opening this ticket later. Reference the heading by its id even if you already render that heading visually, because the visible heading and the accessible name are two different systems and only the association guarantees they stay in sync. If your modal is portaled to the end of the <body>, which most modern component libraries do, confirm the referenced id still resolves after the portal moves the DOM node. Keep the name short and specific: "Delete this project?" beats "Confirmation," because it tells the user what they are confirming. And when a single component powers many dialogs, generate the title id dynamically so two open-and-close cycles never leave duplicate ids in the tree, which would quietly break the aria-labelledby lookup.

Frequently Asked Questions

Can I Use the Native <dialog> Element Instead?

Yes, and it is a solid choice, but it still needs a name. A native <dialog> without a title, aria-label, or aria-labelledby announces just as poorly, so name it the same way.

Which Is Better Here, aria-label or aria-labelledby?

Reach for aria-labelledby whenever a visible heading exists, since it keeps the spoken and visible names in sync. Use aria-label only when no visible title is present.

Do I Need Both a Name and aria-modal?

They solve different problems. The accessible name tells users what the dialog is; aria-modal="true" tells assistive tech to treat content behind it as inert. Ship both, plus a real focus trap.

When Should I Choose alertdialog Over dialog?

Use alertdialog for urgent, interruptive messages that need an immediate response, such as a destructive-action confirmation. For everything else, dialog is the right role.

Need a full technical audit?

Neova runs deep crawls that catch issues like this across your whole site.

在您自己的网站上找到它

Neova 在每次抓取时都会运行此检查项和其他所有检查项,然后把修复方法写成工单交给您的团队。

  • 适用于 Mac、Windows 和 Linux 的桌面应用
  • 全部 696 项检查,每项都附来源
  • Search Console 和 Analytics 4,以只读方式连接
  • 工单发送到 Jira、Linear 和 Asana

下载 Neova Desktop Free 套餐,或免费试用 Solo 14 天,无需银行卡。

全部无障碍检查 · 指南 · 检查项库

作者:Neova Labs · 返回检查项库