You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(ByLabelText): improve error message for invalid labels (#720)
* fix(ByLabelText): improve error message when label is associated with non-labellable elements (#716)
* fix(ByLabelText) test coverage for #716
Co-authored-by: Ioannis Papadopoulos <[email protected]>
"Found a label with the text of: alone, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.
363
363
364
364
<div>
365
-
<label>
365
+
<label
366
+
for="foo"
367
+
>
366
368
All alone label
367
369
</label>
368
370
</div>"
@@ -407,6 +409,114 @@ test('label with children with no form control', () => {
"Found a label with the text of: /Label/, however the element associated with this label (<div />) is non-labellable [https://html.spec.whatwg.org/multipage/forms.html#category-label]. If you really need to label a <div />, you can use aria-label or aria-labelledby instead.
425
+
426
+
<div>
427
+
428
+
429
+
<div>
430
+
431
+
432
+
<label
433
+
for="div1"
434
+
>
435
+
Label 1
436
+
</label>
437
+
438
+
439
+
<div
440
+
id="div1"
441
+
>
442
+
443
+
Hello
444
+
445
+
</div>
446
+
447
+
448
+
</div>
449
+
450
+
451
+
</div>"
452
+
`)
453
+
})
454
+
455
+
test('multiple labels with non-labellable elements',()=>{
"Found a label with the text of: /Label/, however the element associated with this label (<span />) is non-labellable [https://html.spec.whatwg.org/multipage/forms.html#category-label]. If you really need to label a <span />, you can use aria-label or aria-labelledby instead.
472
+
473
+
Found a label with the text of: /Label/, however the element associated with this label (<p />) is non-labellable [https://html.spec.whatwg.org/multipage/forms.html#category-label]. If you really need to label a <p />, you can use aria-label or aria-labelledby instead.
`Found a label with the text of: ${text}, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.`,
`Found a label with the text of: ${text}, however the element associated with this label (<${tagName} />) is non-labellable [https://html.spec.whatwg.org/multipage/forms.html#category-label]. If you really need to label a <${tagName} />, you can use aria-label or aria-labelledby instead.`,
163
+
)
164
+
.join('\n\n'),
165
+
container,
166
+
)
167
+
}else{
168
+
throwgetConfig().getElementError(
169
+
`Found a label with the text of: ${text}, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.`,
170
+
container,
171
+
)
172
+
}
156
173
}else{
157
174
throwgetConfig().getElementError(
158
175
`Unable to find a label with the text of: ${text}`,
0 commit comments