-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add a11y-no-static-element-interactions
compiler rule
#8251
feat: add a11y-no-static-element-interactions
compiler rule
#8251
Conversation
@timmcca-be is attempting to deploy a commit to the Svelte Team on Vercel. A member of the Team first needs to authorize it. |
a11y-no-static-element-interactions
compiler rulea11y-no-static-element-interactions
compiler rule
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Thank you for implementing this! |
Hello there! I just took a quick look at your PR and it looks like both your PR and my PR deals with checking if an element is non-interactive and/or static. Your PR has a new function [edited because clarity] |
I feel like a mix of both would be best: Your internal enum paired with methods that wrap it into simple boolean methods (like |
Looks like #8167 is going to release ahead of this, so once that is merged I'll update this PR |
@timmcca-be #8167 has been merged. Would you be able to rebase this PR? Thanks! |
8e311cd
to
cae0fae
Compare
@benmccann done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Hi there, is there a way to disable this rule in our own projects? Accessibility is a noble goal but doesn't make sense in our project, though we still love using Svelte. Thanks! |
If you're using VS Code or some other IDE that uses the Svelte language server you can use this setting and if you're using |
Ah, that error is coming from eslint - I think it's not silenceable there yet. Could you open an issue over at https://github.com/sveltejs/eslint-plugin-svelte asking for a feature request to silence specific Svelte compiler warnings? |
Here is a relevant issue, is this what you're looking for? sveltejs/eslint-plugin-svelte#311 |
Ref: #820
This adds the
no-static-element-interactions
rule fromeslint-plugin-jsx-a11y
as a compiler rule. It is tripped if an element with no semantic meaning on the accessibility layer (e.g.div
,a
withouthref
,header
when it is not a direct descendant ofbody
) does not have arole
and has an interactive handler (e.g.on:click
,on:mousedown
).This implementation follows the options from the recommended config by the ESLint plugin. That means:
on:click
on:mousedown
on:mouseup
on:keypress
on:keydown
on:keyup
In the ESLint plugin's default state, it disallows dynamic role values and checks for every
focus
,keyboard
, andmouse
handler. If we want to do this, we can remove the dynamic role check and copy the relevant handlers fromindex.d.ts
.Note that this PR also removes
generic
fromnon_interactive_roles
insrc/compiler/compile/utils/a11y.ts
. It is also excluded from the associated array ineslint-plugin-jsx-a11y
, and removing it made the new rule behave correctly, so I believe its inclusion was a bug. This did not affect any of the tests for the existing a11y rules, but I suspect it may still be a breaking change in some rare cases.New breaking change here
no-static-element-interactions
fromeslint-plugin-jsx-a11y
, configured with the options from the plugin's recommended configBefore submitting the PR, please make sure you do the following
[feat]
,[fix]
,[chore]
, or[docs]
.Tests
npm test
and lint the project withnpm run lint