简体   繁体   English

更新后Aria-live不说标签

[英]Aria-live doesn't say label after updates

I have this piece of HTML which is updated dynamically with JS. 我有一段HTML,可以用JS动态更新。 The screen reader only reads out the new value when they get updated. 屏幕阅读器仅在更新后读取新值。 It doesn't say the label of the input who was updated. 它没有说更新输入的标签。

<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>

I have tried to use aria-labelledby , aria-describedby , role="alert" and aria-label but no results, only the value of the input and never his label. 我尝试使用aria-labelledbyaria-describedbyrole="alert"aria-label但是没有结果,只有输入值,而不是他的标签。

From all my research on Google and StackOverflow, I didn't manage to found a proper answer. 根据我对Google和StackOverflow的所有研究,我没有找到合适的答案。

I'm using NVDA in Firefox as a screen reader. 我正在Firefox中使用NVDA作为屏幕阅读器。

Thank you for your help. 谢谢您的帮助。

The only time a label should be read by a screen-reader is when focus is placed on its corresponding field. 屏幕阅读器唯一应读取标签的时间是将焦点放在其相应字段上。

Your input fields are all disabled. 您的输入字段全部被禁用。 Therefore the labels wouldn't be read since you can't focus into the fields. 因此,由于您无法专注于这些字段,因此不会读取标签。

Remove your aria-live and aria-atomic from your input fields. 从输入字段中删除aria-live和aria-atomic。 They are unusable on input fields. 它们在输入字段上不可用。 Aria-live is triggered on DOM change within the container it's assigned to. Aria-live在分配给它的容器内的DOM更改时触发。 An input field is not a container. 输入字段不是容器。 Also, labels shouldn't be announced that way anyway. 另外,标签无论如何也不应以这种方式宣布。

If you want to announce a change to the DOM I would suggest injecting content into an empty aria-live div at the bottom of your page and hide it accessibly. 如果您想宣布对DOM的更改,建议您将内容注入到页面底部的空aria-live div中,并以可访问的方式隐藏它。

Here is a working example with one static label and 3 dynamic labels. 这是一个带有一个静态标签和3个动态标签的工作示例。 One uses the "disabled" attribute, and one uses aria-disabled so that it can still receive focus. 一种使用“禁用”属性,另一种使用禁用aria的功能,以便它仍然可以接收焦点。 An announcement about the rendering of the new labels is also featured using an accessibly-hidden aria-live container. 还使用可访问隐藏的aria-live容器发布有关新标签渲染的公告。

This has been tested in NVDA in FF, JAWS in IE, and VO in Safari. 已在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); }()); 
 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); } 
 <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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM