Skip to content

Commit e7f492c

Browse files
paularmstrongKent C. Dodds
authored and
Kent C. Dodds
committed
fix: allow any element as valid for aria-labelledby (#274)
1 parent e87c9b0 commit e7f492c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/__tests__/element-queries.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,19 @@ test('can get elements labelled with aria-labelledby attribute', () => {
197197
expect(getByLabelText('Section One').id).toBe('section-one')
198198
})
199199

200+
test('can get sibling elements with aria-labelledby attrib ute', () => {
201+
const {getAllByLabelText} = render(`
202+
<div>
203+
<svg id="icon" aria-labelledby="icon-desc"></svg>
204+
<span id="icon-desc">Tacos</span>
205+
</div>
206+
`)
207+
208+
const result = getAllByLabelText('Tacos')
209+
expect(result).toHaveLength(1)
210+
expect(result[0].id).toBe('icon')
211+
})
212+
200213
test('get can get form controls by placeholder', () => {
201214
const {getByPlaceholderText} = render(`
202215
<input id="username-id" placeholder="username" />,

src/queries/label-text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function queryAllByLabelText(
6363
const possibleAriaLabelElements = queryAllByText(container, text, {
6464
exact,
6565
normalizer: matchNormalizer,
66-
}).filter(el => el.tagName !== 'LABEL') // don't reprocess labels
66+
})
6767

6868
const ariaLabelledElements = possibleAriaLabelElements.reduce(
6969
(allLabelledElements, nextLabelElement) => {

0 commit comments

Comments
 (0)