Skip to content

Commit 3064a25

Browse files
committed
share html example between frameworks
1 parent fff5c2d commit 3064a25

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

docs/api-queries.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,9 @@ getByLabelText(
5656
This will search for the label that matches the given [`TextMatch`](#textmatch),
5757
then find the element associated with that label.
5858

59-
<!--DOCUSAURUS_CODE_TABS-->
60-
61-
<!--Native-->
62-
63-
```javascript
64-
import {getByLabelText} from 'dom-testing-library'
65-
66-
const container = document.body
67-
const inputNode = getByLabelText(container, 'Username')
68-
69-
// This will find the input node for the following DOM structures:
59+
The example below will find the input node for the following DOM structures:
7060

61+
```js
7162
// for/htmlFor relationship between label and form element id
7263
<label for="username-input">Username</label>
7364
<input id="username-input" />
@@ -89,16 +80,17 @@ const inputNode = getByLabelText(container, 'Username')
8980
// Take care because this is not a label that users can see on the page,
9081
// so the purpose of your input must be obvious to visual users.
9182
<input aria-label="username" />
83+
```
9284

93-
// It will NOT find the input node for label text broken up by elements,
94-
// like this:
95-
<label>
96-
<span>Username</span> <input />
97-
</label>
98-
// For this case, you can provide a `selector` in the options:
99-
const inputNode = getByLabelText(container, 'username', {
100-
selector: 'input',
101-
})
85+
<!--DOCUSAURUS_CODE_TABS-->
86+
87+
<!--Native-->
88+
89+
```javascript
90+
import { getByLabelText } from 'dom-testing-library'
91+
92+
const container = document.body
93+
const inputNode = getByLabelText(container, 'Username')
10294
```
10395

10496
<!--React-->
@@ -119,11 +111,19 @@ cy.getByLabelText('username').should('exist')
119111

120112
<!--END_DOCUSAURUS_CODE_TABS-->
121113

122-
> **Note**
123-
>
124-
> This method will throw an error if it cannot find the node. If you don't want
125-
> this behavior (for example you wish to assert that it doesn't exist), then use
126-
> `queryByLabelText` instead.
114+
It will NOT find the input node for label text broken up by elements. For this
115+
case, you can provide a `selector` in the options:
116+
117+
```html
118+
<label> <span>Username</span> <input /> </label>
119+
```
120+
121+
```js
122+
const container = document.body
123+
const inputNode = getByLabelText(container, 'username', {
124+
selector: 'input',
125+
})
126+
```
127127

128128
### `ByPlaceholderText`
129129

0 commit comments

Comments
 (0)