Can all elements have role attribute?
m98 opened this issue · comments
Can all elements have a role attribute?
I could not find accepted roles for the "div" tag
A list of HTML elements and their allowed roles can be found in https://www.w3.org/TR/html-aria/#docconformance.
The "div" tag can have any role.
How would you use aria-query if we included this information?
Hey @eps1lon! Nice to see you here too 👍
Actually I don't use the area-query
itself, but I just look at it as a source to know available roles I can assign to each element if necessary. I need it more because of the testing-library's getByRole
Actually it's not very clear what's the default role of an element, or what is the available role to assign to each element.
My IDE does not give me any hint for that! like I'm not sure how can I select a div by using getByRole
as I don't know what's the current role of the div
. And I know I can't just assign a random string as role
, and I have to use one of the predefined values. I look at this repo as a reference to find predefined values for the role attribute.
The linked document also has a column for "Implicit ARIA semantics" which is what you would call a "default role".
The W3C HTML spec list these as well (which we link to from https://testing-library.com/docs/dom-testing-library/api-queries#byrole). But I see that the link isn't all that helpful. The html-aria table is way more useful.
A word of warning though: Don't add role
attributes to query an element. Only add it if you know that this element implements that pattern.
Let's move this discussion to the testing-library-docs repo. That repo seems more appropriate for your issue.
Closing in favor of testing-library/testing-library-docs#561