[英]How can I systematically disable certain irrelevant a11y warnings when compiling with Svelte?
Here is the warning I get when I compile a component with an img that lacks an alt attribute:这是我在使用缺少 alt 属性的 img 编译组件时收到的警告:
Plugin svelte: A11y: <img> element should have an alt attribute
All developers will agree A11y is a good thing;所有开发者都会同意 A11y 是个好东西; except in my case, it would serve only to annoy a screen reader.
除了我的情况,它只会惹恼屏幕阅读器。 I'm making a game engine and my objects look like this:
我正在制作一个游戏引擎,我的对象如下所示:
SVG image, item label. SVG 图像,项目 label。 To the screen reader, this would read "Fabric Scrap Fabric Scrap";
对于屏幕阅读器,这将显示为“Fabric Scrap Fabric Scrap”; it really doesn't make sense to have an alt attribute here, but the best the docs have to offer me is that I can clutter up my code like such:
在这里有一个 alt 属性真的没有意义,但是文档必须为我提供的最好的东西是我可以像这样混乱我的代码:
<!-- svelte-ignore a11y-autofocus -->
<input bind:value={name} autofocus>
I really want to avoid that, so how can I get Svelte to stop showing me this specific error?我真的很想避免这种情况,那么我怎样才能让 Svelte 停止向我显示这个特定错误呢? Ideally without disabling the A11y module as a whole.
理想情况下不禁用整个 A11y 模块。
You can disable warnings at the project level.您可以在项目级别禁用警告。
If you're using rollup, warnings can be suppressed by providing a custom onwarn
handler:如果您使用汇总,可以通过提供自定义
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)
}
})
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.