Description
Describe the bug
This perfectly legit code...
<div on:click={handler}><slot/></div>
...produces these a11y errors...
A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event. svelte(a11y-click-events-have-key-events)
A11y: <div> with click handler must have an ARIA role svelte(a11y-no-static-element-interactions)
This is wrong in two ways:
- Events propagate. Simply attaching an event to a non-interactive element has no effect in and of itself on a11y or the semantics on which AT relies. (If it does -- if user agents do indeed infer the role of an element from the event listeners that have been attached to it -- then I'm wrong. But that would be...ugh...their problem?)
- More importantly. The a11y errors and suggestions Svelte displays encourage, rather than discourage, bad a11y practices. "Sure buddy, it's ok to make your div a link. Just mess around until you hit on the right combination." This can easily lead to the following...
<div on:click={handler} role="button" tabindex="0" on:keyup={() => {}}>
<slot/>
</div>
...which passes Svelte's a11y linting with flying colors even though it is obviously tripe. Less obviously, if my intention was simply to have the div
listen for clicks, rather than turn it into a button, then the linter, rather than helping, has done significant harm, both to the accessibility of the end product and to my (the developer's) understanding of a11y and javascript.
Fix: A11y linting rules that rely on Svelte event directives (e.g. on:eventName
) should be gotten rid of. There's no way (at least that I can think of) to divine what the presence of a listener implies.
There's an issue on this repo where folks have been talking about ways to disable a11y warnings in VsCode, etc. It's been open for two and a half years. Wouldn't it be better just to fix the the underlying problems rather than continue to tell people that they can skirt around the defects by doing this, that and the other?