sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
78.85k stars 4.14k forks source link

Wrong a11y wargning on <dialog> with autofocus attribute #9225

Open shadow-identity opened 1 year ago

shadow-identity commented 1 year ago

Describe the bug

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.

Reproduction

<dialog autofocus>
    I'm a dialog
</dialog>

https://svelte.dev/repl/483135a2842e4da6ba6f24ea63430cf2?version=4.2.0

Logs

No response

System Info

N/A

Severity

annoyance

brunnerh commented 1 year ago

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.

shadow-identity commented 1 year ago

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.