Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/__tests__/element-queries.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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