Skip to content

Commit 395d5c5

Browse files
authored
fix(ByLabelText): aria-labelledby query selector (#708)
1 parent 44e1d5c commit 395d5c5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/__tests__/element-queries.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ test('can get form controls by label text', () => {
178178
<span id="seventh-label-one">7th one</span>
179179
<input aria-labelledby="seventh-label-one" id="seventh-id" />
180180
</div>
181+
<div>
182+
<label id="eighth.label">8th one</label>
183+
<input aria-labelledby="eighth.label" id="eighth.id" />
184+
</div>
181185
</div>
182186
`)
183187
expect(getByLabelText('1st').id).toBe('first-id')
@@ -191,6 +195,7 @@ test('can get form controls by label text', () => {
191195
expect(getByLabelText('6th one 6th two').id).toBe('sixth-id')
192196
expect(getByLabelText('6th one 6th two 6th three').id).toBe('sixth-id')
193197
expect(getByLabelText('7th one').id).toBe('seventh-id')
198+
expect(getByLabelText('8th one').id).toBe('eighth.id')
194199
})
195200

196201
test('can get elements labelled with aria-labelledby attribute', () => {

src/queries/label-text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function queryAllByLabelText(
8181
: []
8282
const labelsValue = labelsId.length
8383
? labelsId.map(labelId => {
84-
const labellingElement = container.querySelector(`[id=${labelId}]`)
84+
const labellingElement = container.querySelector(`[id="${labelId}"]`)
8585
return getLabelContent(labellingElement)
8686
})
8787
: Array.from(labelledElement.labels).map(label => {

0 commit comments

Comments
 (0)