当讲述人忽略元素上的 aria-label 而 aria-label 的值与元素的内容相同时,是否有规则或设置?

Is there a rule or setting when Narrator ignore aria-label on element while aria-label's value same as element 's content?

当我将aria-label的值设置为与按钮内容相同时,屏幕-reader无法读出aria-label。

<button aria-label="Close"><span>Close</span></button>

但是当我改变 aria-label 的值不同于按钮的内容时,屏幕-reader 读出 aria-label。

<button aria-label="Close X"><span>Close</span></button>

当讲述人忽略元素上的 aria-label 而 aria-label 的值与元素的内容相同时,是否有规则或设置?

感谢您的帮助。

没有关于这个的任何约定。

By default, an HTML element will use its text content as the accessibility label. If an element has aria-label, the accessible name becomes the string that it's passed in the attribute.

您的代码适用于 chrome 屏幕 reader 扩展。 请查看 this link 了解更多信息。

还有一个 chrome 扩展可以帮助您解决丢失的 ARIA 标签、误用的 ARIA 角色以及名为 ARIA DevTools 的不完整键盘。这是 link

你说的是 accessible name. An element can only have one accessible name and it's announced by the screen reader when you navigate to that element, along with it's role and value or state, as per WCAG 4.1.2. (It can also have an accessible description.)

可访问名称是使用“Accessible Name and Description Computation 1.1”中定义的优先顺序计算的。它本质上是一个很大的“if then else”语句,当其中一个条件为真时,其余的将被忽略。优先顺序(这里有点过分简化,但您可以在上述 link 中查看详细信息)是:

  1. aria-labelledby
  2. aria-label
  3. <label> 元素
  4. 来自内容
  5. 来自工具提示

在您的示例中,您有 两个 个可访问名称来源,#2 和 #4。 aria-label(#2,“Close X”)将首先被找到,因此内容(#4,“Close”)将被忽略。