@@ -585,6 +585,8 @@ if (typeof jQuery === 'undefined') {
585585 toggle : true
586586 }
587587
588+ Collapse . ARIA_EXPANDED_ALLOWED_ROLES = [ 'application' , 'button' , 'checkbox' , 'combobox' , 'gridcell' , 'link' , 'listbox' , 'menuitem' , 'row' , 'rowheader' , 'tab' , 'treeitem' ]
589+
588590 Collapse . prototype . dimension = function ( ) {
589591 var hasWidth = this . $element . hasClass ( 'width' )
590592 return hasWidth ? 'width' : 'height'
@@ -615,7 +617,11 @@ if (typeof jQuery === 'undefined') {
615617 this . $element
616618 . removeClass ( 'collapse' )
617619 . addClass ( 'collapsing' ) [ dimension ] ( 0 )
618- . attr ( 'aria-expanded' , true )
620+
621+ // the aria-expanded attribute is only allowed when the element has an allowed role
622+ if ( Collapse . ARIA_EXPANDED_ALLOWED_ROLES . includes ( this . $element . attr ( 'role' ) ) ) {
623+ this . $element . attr ( 'aria-expanded' , true )
624+ }
619625
620626 this . $trigger
621627 . removeClass ( 'collapsed' )
@@ -655,7 +661,11 @@ if (typeof jQuery === 'undefined') {
655661 this . $element
656662 . addClass ( 'collapsing' )
657663 . removeClass ( 'collapse in' )
658- . attr ( 'aria-expanded' , false )
664+
665+ // the aria-expanded attribute is only allowed when the element has an allowed role
666+ if ( Collapse . ARIA_EXPANDED_ALLOWED_ROLES . includes ( this . $element . attr ( 'role' ) ) ) {
667+ this . $element . attr ( 'aria-expanded' , false )
668+ }
659669
660670 this . $trigger
661671 . addClass ( 'collapsed' )
@@ -696,7 +706,10 @@ if (typeof jQuery === 'undefined') {
696706 Collapse . prototype . addAriaAndCollapsedClass = function ( $element , $trigger ) {
697707 var isOpen = $element . hasClass ( 'in' )
698708
699- $element . attr ( 'aria-expanded' , isOpen )
709+ if ( Collapse . ARIA_EXPANDED_ALLOWED_ROLES . includes ( this . $element . attr ( 'role' ) ) ) {
710+ $element . attr ( 'aria-expanded' , isOpen )
711+ }
712+
700713 $trigger
701714 . toggleClass ( 'collapsed' , ! isOpen )
702715 . attr ( 'aria-expanded' , isOpen )
@@ -2345,14 +2358,12 @@ if (typeof jQuery === 'undefined') {
23452358 . end ( )
23462359 . find ( '[data-toggle="tab"]' )
23472360 . attr ( 'tabindex' , "-1" )
2348- . attr ( 'aria-expanded' , false )
23492361 . attr ( 'aria-selected' , false )
23502362
23512363 element
23522364 . addClass ( 'active' )
23532365 . find ( '[data-toggle="tab"]' )
23542366 . attr ( 'tabindex' , "0" )
2355- . attr ( 'aria-expanded' , true )
23562367 . attr ( 'aria-selected' , true )
23572368
23582369 if ( transition ) {
0 commit comments