I really spent far too much time re-thinking that title.
If you have a search form on your site and you want to be a good accessibility soldier and drop ARIA roles in for landmarks, then you may have wondered where to put role="search". If you’re like me (or many others) then you probably put it directly into the form element. Don’t.
These are the two legal (see below) options (which will also keep the HTML validator from yelling at you):
Clearly you can use other elements instead of a div, and you can nest them in different ways, but what is important is that you do not put the role="search" on the form element.
A proper form already has the form role thanks to its own native semantics. Ignore this incorrect statement on that same page:For search facilities, authors SHOULD use the search role and not the generic form role.
Sorry for the whiplash I just caused there, but I want to make sure people aren’t reading the bad advice and assuming I missed it.
The reason you don’t want to override the native role is that the search role doesn’t replicate the form role, and therefore this matters:
Adding an ARIA role overrides the native role semantics in the accessibility tree which is reported via the accessibility API, and therefore ARIA indirectly affects what is reported to a screen reader or other assistive technology.
Also, doing this violates the second rule of ARIA use:
Do not change native semantics, unless you really have to.
What real-world impact this has on current ATs is unknown, but my hunch is that it’s minimal. We can’t know what impact it might have as more ATs support ARIA though (obviously).
Arguably a WCAG technique shouldn’t recommend a practice that is generally problematic though.
Can of Worms
In the Gitter chat and on Twitter a few people (including me) wondered aloud why an item cannot accept two roles — such as one landmark role and one widget role. The risk, of course, is that invariably roles have functional overlaps and there is no good way for a browser nor AT to tease out which one in conflict should win.
Please note that the HTML specification is not updated to reflect this yet and the Nu HTML validator does not reflect the change yet either (see above for the change request). If you submit anything with <form role="search"> to the validator it will generate an error.