Skip to content

Commit 9024115

Browse files
[findByLabelText] Adds a bad example using for w/ a non-form element
This came up at my work today. An engineer assumed that any DOM nodes that have share `for` and `id` attrs can be queried by `findByLabelText`. But really, it's not semantically correct to do this or to expect `findByLabelText` to work in this way. I think making that explicit in the docs would be good
1 parent bbdf4b4 commit 9024115

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

docs/dom-testing-library/api-queries.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ If it is important that you query an actual `<label>` element you can provide a
214214
Username
215215
<textarea></textarea>
216216
</label>
217+
218+
// for/htmlFor between label and an element that is not a form element
219+
<section id="photos-section">
220+
<label for="photos-section">Photos</label>
221+
</section>
217222
```
218223

219224
```js

0 commit comments

Comments
 (0)