-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Get rid of "A11y: Avoid using autofocus" warning #6629
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
Comments
IMO one of the reasons why it's flagged as a warning is because Svelte handes But a flaw with the above is that if you have elements that are conditionally rendered, and within it has the
Between both, I'd rather be screamed by Svelte so that I know I'm doing something bad. Unless if you're trying to mimic the behaviour for initial page load (not conditional rendering), then you can use That's my 2c. For completeness, duplicate of #1865 |
Warnings make sense in two cases:
In this case both are false. Therefore this warning needs to go. (and all other warnings that don't fit into those two categories) |
Sounds like the definition for "errors". Warnings can be used for a variety of reasons to warn users that something bad may happen, though it's ok if you ignore it. So I'd disagree with this statement.
There is an alternative, I still think that this warning is here to stay. |
This warning is reasonable in my opinion. You should have a very specific use-case (like search engines, which were the only examples you mentioned) to make Also just because some popular websites does something doesn't mean you should too. WebAIM Million 2021 revealed that 97.4% of the top 1 million home pages had detectable WCAG 2 errors (not warnings). They found that 40% of home pages had skipping heading levels; developers aren't exactly great at picking the right tool for the job, not even the developers of the most popular sites. If Svelte can warn for stuff like this that's a good thing, and if you have the option to ignore this because you have a legitimate reason to use it, that's a good thing too. Also, it seems like this issue has already been discussed between Rich and Conduitry (see #882) and it was closed in favor of |
Just for completeness: The reason why |
Amen. |
Closing as duplicate of #1865 |
This warning makes no sense inside a |
I came here after getting this warning during the build process and was confused as to why. The mdn webdocs specifically says "The autofocus attribute should be added to the element the user is expected to interact with immediately upon opening a modal dialog." After reading the comments I understand why there's a warning, but I'm not convinced it should say "Avoid using autofocus". You could argue that even when taking Svelte out of the equation the autofocus attribute can be misused and result in a similar bad UX, it's all about using the attribute correctly, not avoiding it altogether. The official Svelte documentation just makes things confusing, it directly contradicts The mdn webdocs (a web standard) and doesn't bother explaining why. Imo the warning and documentation should be at least be reworded to something more along the lines of "autofocus can mess up the focus order for screenreaders and similar assistive technologies, use with caution" stating th the warning can be disabled with the use of |
@bfontaine This is true, but it says the same thing in the actual HTML standard: (which anyone can contribute to as well) |
Describe the bug
Let's call this warning for what it is - a bug.
autofocus
is 100% legitimate feature of HTML5, and just because it can be abused it shouldn't be triggering warnings.Just some of many websites that use
autofocus
:Warning on something that is key feature a lot of major websites use makes no sense. The alternative of focusing the main input with js is not an improvement at all.
I'm not the first person affected. This has been raised many times in the past, and unreasonably closed without fixing.
Warning systems are useless if most of the warnings are of very low quality like this one; and we should absolutely be getting rid of bad warnings in default configuration. If someone wants to enable extra strict warnings, this should not be default at least.
Reproduction
Legitimately use
<input autofocus>
, and get this silly warning.Logs
(!) Plugin svelte: A11y: Avoid using autofocus
The text was updated successfully, but these errors were encountered: