@@ -65,8 +65,8 @@ function isInaccessible(element, options = {}) {
65
65
function getImplicitAriaRoles ( currentNode ) {
66
66
// eslint bug here:
67
67
// eslint-disable-next-line no-unused-vars
68
- for ( const { selector , roles} of elementRoleList ) {
69
- if ( currentNode . matches ( selector ) ) {
68
+ for ( const { match , roles} of elementRoleList ) {
69
+ if ( match ( currentNode ) ) {
70
70
return [ ...roles ]
71
71
}
72
72
}
@@ -75,7 +75,7 @@ function getImplicitAriaRoles(currentNode) {
75
75
}
76
76
77
77
function buildElementRoleList ( elementRolesMap ) {
78
- function makeElementSelector ( { name, attributes = [ ] } ) {
78
+ function makeElementSelector ( { name, attributes} ) {
79
79
return `${ name } ${ attributes
80
80
. map ( ( { name : attributeName , value, constraints = [ ] } ) => {
81
81
const shouldNotExist = constraints . indexOf ( 'undefined' ) !== - 1
@@ -101,6 +101,31 @@ function buildElementRoleList(elementRolesMap) {
101
101
return rightSpecificity - leftSpecificity
102
102
}
103
103
104
+ function match ( element ) {
105
+ return node => {
106
+ let { attributes = [ ] } = element
107
+ // https://github.com/testing-library/dom-testing-library/issues/814
108
+ const typeTextIndex = attributes . findIndex (
109
+ attribute =>
110
+ attribute . value &&
111
+ attribute . name === 'type' &&
112
+ attribute . value === 'text' ,
113
+ )
114
+ if ( typeTextIndex >= 0 ) {
115
+ // not using splice to not mutate the attributes array
116
+ attributes = [
117
+ ...attributes . slice ( 0 , typeTextIndex ) ,
118
+ ...attributes . slice ( typeTextIndex + 1 ) ,
119
+ ]
120
+ if ( node . type !== 'text' ) {
121
+ return false
122
+ }
123
+ }
124
+
125
+ return node . matches ( makeElementSelector ( { ...element , attributes} ) )
126
+ }
127
+ }
128
+
104
129
let result = [ ]
105
130
106
131
// eslint bug here:
@@ -109,7 +134,7 @@ function buildElementRoleList(elementRolesMap) {
109
134
result = [
110
135
...result ,
111
136
{
112
- selector : makeElementSelector ( element ) ,
137
+ match : match ( element ) ,
113
138
roles : Array . from ( roles ) ,
114
139
specificity : getSelectorSpecificity ( element ) ,
115
140
} ,
0 commit comments