Skip to content
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

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

Open
shadow-identity opened this issue Sep 18, 2023 · 2 comments
Open

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

shadow-identity opened this issue Sep 18, 2023 · 2 comments
Labels

Comments

@shadow-identity
Copy link

shadow-identity commented Sep 18, 2023

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
Copy link
Member

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...

  • on an interactive element if it is not the first but you want to focus it instead
  • on the dialog if there are interactive elements inside but you do not want to focus those

I guess a common case would be a close button you want to skip, though.

@shadow-identity
Copy link
Author

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.

@dummdidumm dummdidumm added the a11y label Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants