[英]Screen reader - Only read element with role="alert" and not on focus
I'm building a filter for a site that needs to work with a screen reader and i'm currently facing this problem.我正在为需要使用屏幕阅读器的网站构建过滤器,而我目前正面临这个问题。
The filter is built in a modal that houses a set of checkboxes and one button that displays how many hits the user has got after selecting each checkbox.该过滤器构建在一个模态中,该模态包含一组复选框和一个按钮,该按钮显示用户在选中每个复选框后获得的点击次数。 The text in the button is dynamic and changes depending on the number of hits there is after a checkbox has been selected.按钮中的文本是动态的,并且会根据选中复选框后的点击次数而变化。
The text in the button says "Show X hits".按钮中的文字显示“显示 X 次匹配”。 I have added a role="alert" to the button so that the screen reader pick ups imidiatly if the value/text changes in the button.我在按钮上添加了一个 role="alert" ,以便屏幕阅读器在按钮中的值/文本发生变化时立即获取。
My question is, is it possible for the screen reader to read the text "X hits" when the button is triggerd by the role="alert" and the text "Show X hits" when the user navigtes down to the button?我的问题是,当按钮被 role="alert" 触发时,屏幕阅读器是否可以阅读文本“X hits”,而当用户向下导航到按钮时,文本“Show X hits”?
Example of my button:我的按钮示例:
<button type="button" role="alert" class="btn btn-primary" v-on:click="search()">
<span class="sr-only">{{amount}} hits.</span>
<span>Show {{amount}} hits.</span>
</button>
UPDATE Managed to get a working solution using this:更新设法使用此方法获得有效的解决方案:
<button type="button" class="btn btn-primary" v-on:click="search()">
<span aria-hidden="true">Show {{amount}} hits.</span>
<div class="sr-only">
<span>Show</span>
<span role="alert">{{amount}} hits</span>
</div>
</button>
You should not put a live region inside a button.您不应该将活动区域放在按钮内。 The button
role has presentational children . button
角色有presentational children 。
That means that, as per ARIA standard, the role of any child of the button should be ignored.这意味着,根据 ARIA 标准,应该忽略按钮的任何子项的角色。 This includes role="alert"
.这包括role="alert"
。
Maybe it works in your browser/screen reader combination, but I wouldn't rely on that.也许它适用于您的浏览器/屏幕阅读器组合,但我不会依赖它。
I don't see a reason why the text would be inside the button anyway, since your are hiding it.我看不出文本为什么会在按钮内的原因,因为你隐藏了它。
So I'd recommend this:所以我推荐这个:
<button type="button" class="btn btn-primary" v-on:click="search()">
Show {{amount}} hits.
</button>
<div class="sr-only" role="alert">{{amount}} hits</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.