【发布时间】:2018-06-11 22:41:40
【问题描述】:
我正在尝试让一个 vue 组件在我的网站上发生不同事件时动态地向屏幕阅读器宣布信息。
我已经让它工作到单击按钮将用文本填充aria-live="assertive" 和role="alert" 的范围。这在第一次时运行良好,但是,单击具有类似行为的其他按钮会导致 NVDA 在读取新文本之前读取之前的文本两次。这似乎发生在 vue 中,但没有使用 jquery 进行类似的设置,所以我猜这与 vue 呈现给 DOM 的方式有关。
我希望有某种方法可以解决此问题,或者可能是一种更好的方法来向没有此问题的用户阅读文本。非常感谢任何帮助。
Here is a simple component我在一个工作代码沙箱中设置以显示我遇到的问题(导航到 components/HelloWorld.vue 以获取代码)-注意:此沙箱已根据以下答案进行了更改强>。该组件的完整代码如下:
export default {
name: "HelloWorld",
data() {
return {
ariaText: ""
};
},
methods: {
button1() {
this.ariaText = "This is a bunch of cool text to read to screen readers.";
},
button2() {
this.ariaText = "This is more cool text to read to screen readers.";
},
button3() {
this.ariaText = "This text is not cool.";
}
}
};
<template>
<div>
<button @click="button1">1</button>
<button @click="button2">2</button>
<button @click="button3">3</button><br/>
<span role="alert" aria-live="assertive">{{ariaText}}</span>
</div>
</template>
【问题讨论】:
标签: javascript vue.js accessibility wai-aria nvda