Skip to content

Commit

Permalink
fix: allow any element as valid for aria-labelledby (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
paularmstrong authored and Kent C. Dodds committed Jun 1, 2019
1 parent e87c9b0 commit e7f492c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/__tests__/element-queries.js
Expand Up @@ -197,6 +197,19 @@ test('can get elements labelled with aria-labelledby attribute', () => {
expect(getByLabelText('Section One').id).toBe('section-one')
})

test('can get sibling elements with aria-labelledby attrib ute', () => {
const {getAllByLabelText} = render(`
<div>
<svg id="icon" aria-labelledby="icon-desc"></svg>
<span id="icon-desc">Tacos</span>
</div>
`)

const result = getAllByLabelText('Tacos')
expect(result).toHaveLength(1)
expect(result[0].id).toBe('icon')
})

test('get can get form controls by placeholder', () => {
const {getByPlaceholderText} = render(`
<input id="username-id" placeholder="username" />,
Expand Down
2 changes: 1 addition & 1 deletion src/queries/label-text.js
Expand Up @@ -63,7 +63,7 @@ function queryAllByLabelText(
const possibleAriaLabelElements = queryAllByText(container, text, {
exact,
normalizer: matchNormalizer,
}).filter(el => el.tagName !== 'LABEL') // don't reprocess labels
})

const ariaLabelledElements = possibleAriaLabelElements.reduce(
(allLabelledElements, nextLabelElement) => {
Expand Down

0 comments on commit e7f492c

Please sign in to comment.