Aria-live在更新后没有说标签

Rap*_*ent 2 accessibility wai-aria aria-live

我有这条用JS动态更新的HTML.屏幕阅读器仅在更新时读取新值.它没有说更新的输入标签.

<ul class="points-transfer-detail-points-calculation clearfix">
    <li>
        <label for="points-to-transfer">{{{ pointsToTransferLabel }}}</label>
        <input id="points-to-transfer" type="text" aria-controls="brand-points points-left-after-transfer" placeholder="XXX,XXX" {{#if disabled }}disabled{{/if}}>
        <p id="points-to-transfer-error" class="points-transfer-detail-form-error" aria-hidden="true" role="alert">{{{ pointsToTransferErrorMessage }}}</p>
    </li>
    <li>
        <label for="brand-points">{{{ brandPointsLabel }}}</label>
        <input id="brand-points" type="text" aria-live="polite" aria-atomic="true" disabled>
    </li>
    <li>
        <label for="points-left-after-transfer">{{{ pointsLeftLabel }}}</label>
        <input id="points-left-after-transfer" type="text" aria-live="polite" aria-atomic="true" disabled>
    </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

我曾尝试使用aria-labelledby,aria-describedby,role="alert"aria-label,但没有结果,只有输入的值,永不他的标签.

从我对Google和StackOverflow的所有研究中,我找不到合适的答案.

我在Firefox中使用NVDA作为屏幕阅读器.

谢谢您的帮助.

hal*_*web 7

屏幕阅读器应该读取标签的唯一时间是将焦点放在相应的字段上.

您的输入字段全部被禁用.因此,无法读取标签,因为您无法将焦点聚焦到字段中.

从输入字段中删除您的aria-live和aria-atomic.它们在输入字段上无法使用.Aria-live在其分配的容器内的DOM更改时触发.输入字段不是容器.此外,标签不应该以这种方式宣布.

如果您想宣布对DOM的更改,我建议将内容注入页面底部的空aria-live div并将其隐藏起来.

这是一个带有一个静态标签和3个动态标签的工作示例.一个使用"禁用"属性,一个使用咏叹调禁用,以便它仍然可以获得焦点.使用可访问隐藏的咏叹调活容器,还宣布了关于渲染新标签的公告.

这已经在FF中的NVDA,IE中的JAWS和Safari中的VO中进行了测试.

(function () {
  function populateLabels () {
    document.querySelector('[for="dogsName"]').appendChild(document.createTextNode('Dog\'s Name'));
    document.querySelector('[for="catsName"]').appendChild(document.createTextNode('Cat\'s Name'));
    document.querySelector('[for="lastName"]').appendChild(document.createTextNode('Last Name'));
  }
  function announceChange () {
    var announcement = "Some new labels have appeared.  They are Last Name, Dog's Name, and Cat's Name.",
        ariaLiveContainer = document.querySelector('[aria-live]');
    ariaLiveContainer.appendChild(document.createTextNode(announcement));
    setTimeout(function () {
      ariaLiveContainer.innerHTML("");
    }, 2000);
  }
  setTimeout(function () {
    populateLabels();
    announceChange();
  }, 3000);
}());
Run Code Online (Sandbox Code Playgroud)
input {
  border: 1px solid black;
}
[disabled],
[aria-disabled="true"] {
  border: 1px solid #ccc;
  background-color: #eee;
}
.acc-hidden { /* Hide only visually, but have it available for screenreaders */
  position: absolute !important;
  display: block;
  visibility: visible;
  overflow: hidden;
  width: 1px;
  height: 1px;
  margin: -1px;
  border: 0;
  padding: 0;
  clip: rect(0 0 0 0);
}
Run Code Online (Sandbox Code Playgroud)
<p>The first label is there on DOM load.  The other three labels come in 3 seconds after DOM load.  An announcement is made about the updated labels.</p>
<form action="">
  <ul>
    <li>
      <label for="firstName">First Name</label>
      <input type="text" name="first-name" id="firstName" />
    </li>
    <li>
      <label for="lastName"></label>
      <input type="text" name="last-name" id="lastName" />
    </li>
    <li>
      <label for="dogsName"></label>
      <input type="text" name="dogs-name" id="dogsName" disabled /> (uses the disabled attribute -- doesn't receive focus)
    </li>
    <li>
      <label for="catsName"></label>
      <input type="text" name="cats-name" id="catsName" aria-disabled="true" /> (uses the aria-disabled="true" attribute -- can receive focus)
    </li>
  </ul>
</form>
<div class="acc-hidden" aria-live="polite"></div>
Run Code Online (Sandbox Code Playgroud)