Wrong a11y wargning on <dialog> with autofocus attribute
#9225closes #9225
feat:
, fix:
, chore:
, or docs:
.packages/svelte/src
, add a changeset (npx changeset
).pnpm test
and lint the project with pnpm lint
Ally warning "Avoid using autofocus" appears on <dialog autofocus>
element definition.
But using of autofocus on dialog or its descendants is recommended by the standard: https://html.spec.whatwg.org/multipage/interactive-elements.html#the-dialog-element
As such, authors should use the autofocus attribute on the descendant element of the dialog that the user is expected to immediately interact with after the dialog opens. If there is no such element, then authors should use the autofocus attribute on the dialog element itself.
<dialog autofocus>
I'm a dialog
</dialog>
https://svelte.dev/repl/483135a2842e4da6ba6f24ea63430cf2?version=4.2.0
No response
N/A
annoyance
It may not be necessary in many cases; as the spec states:
The dialog focusing steps attempt to pick a good candidate for initial focus when a dialog is shown
It looks like browsers will already focus the first interactive element and if there is none, the dialog itself. So you should only need it...
I guess a common case would be a close button you want to skip, though.
Agree that using this attribute could be not necessary, but still recommended and definitely not an error, so should not be treated as an a11y issue.
I'd like to bump this issue since I just encountered it. The MDN docs specifically say to use autofocus
on the <dialog>
when there isn't a specific element that should have first focus.