html icon indicating copy to clipboard operation
html copied to clipboard

Consider conformance guidance for authors to explicitly declare autofocus for dialog element

Open scottaohara opened this issue 3 years ago • 2 comments

Per the dialog initial focus proposal, this unresolved comment has been moved here for further discussion:

As such, authors should use the autofocus attribute on the descendant element of the dialog that the user will expect 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.

Summary of exchange between Domenic and Aaron:

  • This would mean conformance checkers will warn authors if a dialog element doesn't have autofocus specified somewhere in the dialog.
  • agreement that this is probably the right thing to do, but worry about potential warning fatigue or requiring redundant autofocus attributes.

cc @sideshowbarker for thoughts on the matter

scottaohara avatar Mar 15 '22 19:03 scottaohara

This seems like a good thing to require if we think that making web developers think about and make a decision about which element should have autofocus results in a net better UX compared to the default behavior when there's no autofocus.

I'm not so worried about warning fatigue in this case, as long as the message in the conformance checker is understandable and explains the motivation for needing the autofocus attribute.

There's some precedence: the sizes attribute was optional at first and had a default value (100vw). We noticed that many developers omitted the sizes attribute (since it was optional) but the default was not always appropriate. So we made it required, even when you want the default value, and developers who wanted the error to go away had to think about what value to use in sizes.

zcorpan avatar Mar 31 '22 22:03 zcorpan

Regarding the question of which issues in https://github.com/whatwg/html/pull/4184#issuecomment-1072536425 should be considered blocking for writing up a spec of https://github.com/whatwg/html/wiki/dialog--initial-focus,-a-proposal#initial-dialog-focus-logic : This is about whether to include a single sentence in the spec proposal there. And we have at least some positive support for including the sentence, from @zcorpan and the two thumbs-uppers. So I think we should call this resolved, and that sentence should be included in the PR.

domenic avatar Aug 09 '22 09:08 domenic

So I think we should call this resolved, and that sentence should be included in the PR

Great! How do I make a conformance requirement/guidance? Is there an example I could copy?

josepharhar avatar Aug 16 '22 22:08 josepharhar

You can learn more about authoring conformance requirements here: https://html.spec.whatwg.org/#conformance-requirements-for-authors . Searching for "Authors should" in the spec will turn up a few examples of the type we're talking about. For this requirement in particular, I think it's about just keeping the sentence mentioned in the OP, when rewriting the dialog element introduction section.

domenic avatar Aug 19 '22 03:08 domenic

I think it's about just keeping the sentence mentioned in the OP

That sentence is now in the PR

josepharhar avatar Aug 25 '22 21:08 josepharhar