File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -343,6 +343,35 @@ Here are the accessible roles:
343
343
` )
344
344
} )
345
345
346
+ test ( 'explicit role is most specific' , ( ) => {
347
+ const { getByRole} = renderIntoDocument (
348
+ `<button role="tab" aria-label="my-tab" />` ,
349
+ )
350
+
351
+ expect ( ( ) => getByRole ( 'button' ) ) . toThrowErrorMatchingInlineSnapshot ( `
352
+ "Unable to find an accessible element with the role "button"
353
+
354
+ Here are the accessible roles:
355
+
356
+ tab:
357
+
358
+ Name "my-tab":
359
+ <button
360
+ aria-label="my-tab"
361
+ role="tab"
362
+ />
363
+
364
+ --------------------------------------------------
365
+
366
+ <body>
367
+ <button
368
+ aria-label="my-tab"
369
+ role="tab"
370
+ />
371
+ </body>"
372
+ ` )
373
+ } )
374
+
346
375
describe ( 'configuration' , ( ) => {
347
376
let originalConfig
348
377
beforeEach ( ( ) => {
Original file line number Diff line number Diff line change @@ -134,7 +134,13 @@ function getRoles(container, {hidden = false} = {}) {
134
134
return hidden === false ? isInaccessible ( element ) === false : true
135
135
} )
136
136
. reduce ( ( acc , node ) => {
137
- const roles = getImplicitAriaRoles ( node )
137
+ let roles = [ ]
138
+ // TODO: This violates html-aria which does not allow any role on every element
139
+ if ( node . hasAttribute ( 'role' ) ) {
140
+ roles = node . getAttribute ( 'role' ) . split ( ' ' ) . slice ( 0 , 1 )
141
+ } else {
142
+ roles = getImplicitAriaRoles ( node )
143
+ }
138
144
139
145
return roles . reduce (
140
146
( rolesAcc , role ) =>
You can’t perform that action at this time.
0 commit comments