Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Allow any element as valid for aria-labelledby #274

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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