Vae*_*tus 2 accessibility rollupjs svelte svelte-3
这是我在编译带有缺少 alt 属性的 img 的组件时收到的警告:
Plugin svelte: A11y: <img> element should have an alt attribute
Run Code Online (Sandbox Code Playgroud)
所有的开发者都会同意 A11y 是个好东西;除了在我的情况下,它只会惹恼屏幕阅读器。我正在制作一个游戏引擎,我的对象看起来像这样:
SVG 图像,项目标签。对于屏幕阅读器,这将显示为“Fabric Scrap Fabric Scrap”;在这里有一个 alt 属性真的没有意义,但文档必须提供给我的最好的东西是我可以像这样混乱我的代码:
<!-- svelte-ignore a11y-autofocus -->
<input bind:value={name} autofocus>
Run Code Online (Sandbox Code Playgroud)
我真的很想避免这种情况,那么我怎样才能让 Svelte 停止向我展示这个特定的错误呢?理想情况下,无需禁用整个 A11y 模块。
您可以在项目级别禁用警告。
如果您正在使用汇总,则可以通过提供自定义onwarn处理程序来抑制警告:
import svelte from 'rollup-plugin-svelte'
export default {
plugins: [
svelte({
// Warnings are normally passed straight to Rollup. You can
// optionally handle them here, for example to squelch
// warnings with a particular code
onwarn: (warning, handler) => {
// e.g. don't warn on a11y-autofocus
if (warning.code === 'a11y-autofocus') return
// let Rollup handle all other warnings normally
handler(warning)
}
})
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1062 次 |
| 最近记录: |