DOM Environment: Chrome 103.0.5060.114 (Official Build) (64-bit)
Relevant code or config:
<section title="My Section">
some text
</section>
What you did:
screen.getByRole('region')
What happened:
TestingLibraryElementError: Unable to find an accessible element with the role "region"
There are no accessible roles. But there might be some inaccessible roles. If you wish to access them, then set the `hidden` option to `true`. Learn more about this here: https://testing-library.com/docs/dom-testing-library/api-queries#byrole
Ignored nodes: comments, <script />, <style />
<body
data-gr-ext-installed=""
data-new-gr-c-s-check-loaded="14.1067.0"
>
<div
id="root"
>
<section
title="My Section"
>
some text
</section>
</div>
Potential accessibility names are either an alt label, ARIA label, title, or the text content for certain elements. For whatever reason, Testing Library is not treating this <section> as a 'region' when it has an accessible name. Works fine for aria-label and aria-labelledby but not for title.
Suggested solution:
Either fix the aria-query library or @testing-library/dom so it includes proper support for accessibility names using the HTML title attribute. Not sure if this is limited to <section> or if it happens for other elements too.
@testing-library/dom
version: v8.14.0.Relevant code or config:
What you did:
What happened:
Reproduction:
https://codesandbox.io/s/bold-bush-64s8n0?file=/src/App.js
Problem description:
<section>
elements should have an internal browser role ofsection
until you give them an accessible name; in which case, they implicitly have the roleregion
: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sectionPotential accessibility names are either an alt label, ARIA label, title, or the text content for certain elements. For whatever reason, Testing Library is not treating this
<section>
as a'region'
when it has an accessible name. Works fine foraria-label
andaria-labelledby
but not fortitle
.Suggested solution:
Either fix the
aria-query
library or@testing-library/dom
so it includes proper support for accessibility names using the HTMLtitle
attribute. Not sure if this is limited to<section>
or if it happens for other elements too.