You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const{getByLabelText}=render(` <div id="frameworks-row" role="row" aria-label="Frameworks"> <button aria-labelledby="select frameworks-row" id="select" aria-label="Select" type="button">Select</button> <span>Frameworks</span> <span>Other information</span> </div> `)// Do not find `Select Frameworks` because it takes element.textContent // and not `aria-label` for the element with id `frameworks-row`expect(getByLabelText('Select Frameworks').id).toBe('select')expect(getByLabelText('Frameworks').id).toBe('frameworks-row')
What you did:
There are some use cases where we want to labelled an element with aria-labelledby that references an element that has aria-label.
For example, in the template above the button element has a aria-labelledby that references himself (that has aria-label) and the div with id frameworks-row (that has aria-label)
What happened:
The selector getByLabelText('Select Frameworks') does not work because when getting the element with id: frameworks-row, it's not the aria-label that is retrieved but the textContent (here Select Frameworks Other information)
The selector getByLabelText('Select Frameworks') does not work because when getting the element with id: frameworks-row, it's not the aria-label that is retrieved but the textContent (here Select Frameworks Other information)
Hello all :)
Thanks for the library 🔥
@testing-library/dom
version: v10.4.0Relevant code or config:
I made this branch with a test https://github.com/romain-trotard/dom-testing-library/tree/labelledby-multiple-repro and some comments on the code I think we should change.
What you did:
There are some use cases where we want to labelled an element with
aria-labelledby
that references an element that hasaria-label
.For example, in the template above the
button
element has aaria-labelledby
that references himself (that hasaria-label
) and thediv
with idframeworks-row
(that hasaria-label
)What happened:
The selector
getByLabelText('Select Frameworks')
does not work because when getting the element withid
:frameworks-row
, it's not thearia-label
that is retrieved but thetextContent
(hereSelect Frameworks Other information
)Reproduction:
https://github.com/romain-trotard/dom-testing-library/tree/labelledby-multiple-repro
npm run test
Problem description:
The selector
getByLabelText('Select Frameworks')
does not work because when getting the element withid
:frameworks-row
, it's not thearia-label
that is retrieved but thetextContent
(hereSelect Frameworks Other information
)Suggested solution:
Here
dom-testing-library/src/label-helpers.ts
Line 32 in a86c54c
We should get the
aria-label
attribute before gettingtextContent
, like this:But we also need to find a way to concat these labels (when working with
aria-labelledby
) here:dom-testing-library/src/queries/label-text.ts
Lines 67 to 86 in a86c54c
If the bug is acknowledged, I would be happy to make a fix ;)
Thanks :)
The text was updated successfully, but these errors were encountered: