@@ -65,8 +65,8 @@ function isInaccessible(element, options = {}) {
6565function  getImplicitAriaRoles ( currentNode )  { 
6666 // eslint bug here: 
6767 // 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 ) )  { 
7070 return  [ ...roles ] 
7171 } 
7272 } 
@@ -75,7 +75,7 @@ function getImplicitAriaRoles(currentNode) {
7575} 
7676
7777function  buildElementRoleList ( elementRolesMap )  { 
78-  function  makeElementSelector ( { name,  attributes  =   [ ] } )  { 
78+  function  makeElementSelector ( { name,  attributes} )  { 
7979 return  `${ name } ${ attributes  
8080 . map ( ( { name : attributeName ,  value,  constraints =  [ ] } )  =>  {  
8181 const  shouldNotExist  =  constraints . indexOf ( 'undefined' )  !==  - 1  
@@ -101,6 +101,31 @@ function buildElementRoleList(elementRolesMap) {
101101 return  rightSpecificity  -  leftSpecificity 
102102 } 
103103
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+ 
104129 let  result  =  [ ] 
105130
106131 // eslint bug here: 
@@ -109,7 +134,7 @@ function buildElementRoleList(elementRolesMap) {
109134 result  =  [ 
110135 ...result , 
111136 { 
112-  selector :  makeElementSelector ( element ) , 
137+  match :  match ( element ) , 
113138 roles : Array . from ( roles ) , 
114139 specificity : getSelectorSpecificity ( element ) , 
115140 } , 
0 commit comments