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 null labels on hidden inputs #804

Merged
merged 2 commits into from
Nov 3, 2020
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
7 changes: 7 additions & 0 deletions src/__tests__/label-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {getRealLabels} from '../label-helpers'

test('hidden inputs are not labelable', () => {
const element = document.createElement('input')
element.type = 'hidden'
expect(getRealLabels(element)).toEqual([])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the result before your changes? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the change it returns null:

Screenshot 2020-11-03 at 17 44 01

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see the PR and I have opened a PR on the same behaviour because I saw an issue about it.

})
1 change: 1 addition & 0 deletions src/__tests__/queries.find.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ test('find asynchronously finds elements', async () => {
<div role="dialog"></div>
<div role="meter progressbar"></div>
<header>header</header>
<input type="hidden" />
</div>
`)
await expect(findByLabelText('test-label')).resolves.toBeTruthy()
Expand Down
2 changes: 1 addition & 1 deletion src/label-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function getLabelContent(node) {

// Based on https://github.com/eps1lon/dom-accessibility-api/pull/352
function getRealLabels(element) {
if (element.labels !== undefined) return element.labels
if (element.labels !== undefined) return element.labels ?? []

if (!isLabelable(element)) return []

Expand Down