@@ -18,22 +18,25 @@ function queryAllLabelsByText(
18
18
) {
19
19
const matcher = exact ? matches : fuzzyMatches
20
20
const matchNormalizer = makeNormalizer ( { collapseWhitespace, trim, normalizer} )
21
- return Array . from ( container . querySelectorAll ( 'label' ) ) . filter ( label => {
22
- let textToMatch = label . textContent
21
+ return Array . from ( container . querySelectorAll ( 'label,input' ) ) . filter ( node => {
22
+ let textToMatch =
23
+ node . tagName . toLowerCase ( ) === 'label'
24
+ ? node . textContent
25
+ : node . value || null
23
26
24
27
// The children of a textarea are part of `textContent` as well. We
25
28
// need to remove them from the string so we can match it afterwards.
26
- Array . from ( label . querySelectorAll ( 'textarea' ) ) . forEach ( textarea => {
29
+ Array . from ( node . querySelectorAll ( 'textarea' ) ) . forEach ( textarea => {
27
30
textToMatch = textToMatch . replace ( textarea . value , '' )
28
31
} )
29
32
30
33
// The children of a select are also part of `textContent`, so we
31
34
// need also to remove their text.
32
- Array . from ( label . querySelectorAll ( 'select' ) ) . forEach ( select => {
35
+ Array . from ( node . querySelectorAll ( 'select' ) ) . forEach ( select => {
33
36
textToMatch = textToMatch . replace ( select . textContent , '' )
34
37
} )
35
38
36
- return matcher ( textToMatch , label , text , matchNormalizer )
39
+ return matcher ( textToMatch , node , text , matchNormalizer )
37
40
} )
38
41
}
39
42
0 commit comments