Skip to content

Commit d21e8a6

Browse files
mpiotrowiczscottgonzalez
authored andcommitted
Accordion: moving aria-expanded from active tabpanel to active tab. Fixed #9407 - Accordion: aria-expanded attribute on wrong element
(cherry picked from commit f16d0c7)
1 parent a2217b5 commit d21e8a6

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

tests/unit/accordion/accordion_core.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,29 @@ test( "accessibility", function () {
4646

4747
equal( headers.eq( 1 ).attr( "tabindex" ), 0, "active header has tabindex=0" );
4848
equal( headers.eq( 1 ).attr( "aria-selected" ), "true", "active tab has aria-selected=true" );
49-
equal( headers.eq( 1 ).next().attr( "aria-expanded" ), "true", "active tabpanel has aria-expanded=true" );
49+
equal( headers.eq( 1 ).attr( "aria-expanded" ), "true", "active tab has aria-expanded=true" );
5050
equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "false", "active tabpanel has aria-hidden=false" );
5151
equal( headers.eq( 0 ).attr( "tabindex" ), -1, "inactive header has tabindex=-1" );
5252
equal( headers.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
53-
equal( headers.eq( 0 ).next().attr( "aria-expanded" ), "false", "inactive tabpanel has aria-expanded=false" );
53+
equal( headers.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
5454
equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel has aria-hidden=true" );
5555
equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header has tabindex=-1" );
5656
equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
57-
equal( headers.eq( 2 ).next().attr( "aria-expanded" ), "false", "inactive tabpanel has aria-expanded=false" );
57+
equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
5858
equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel has aria-hidden=true" );
5959

6060
element.accordion( "option", "active", 0 );
6161
equal( headers.eq( 0 ).attr( "tabindex" ), 0, "active header has tabindex=0" );
6262
equal( headers.eq( 0 ).attr( "aria-selected" ), "true", "active tab has aria-selected=true" );
63-
equal( headers.eq( 0 ).next().attr( "aria-expanded" ), "true", "active tabpanel has aria-expanded=true" );
63+
equal( headers.eq( 0 ).attr( "aria-expanded" ), "true", "active tab has aria-expanded=true" );
6464
equal( headers.eq( 0 ).next().attr( "aria-hidden" ), "false", "active tabpanel has aria-hidden=false" );
6565
equal( headers.eq( 1 ).attr( "tabindex" ), -1, "inactive header has tabindex=-1" );
6666
equal( headers.eq( 1 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
67-
equal( headers.eq( 1 ).next().attr( "aria-expanded" ), "false", "inactive tabpanel has aria-expanded=false" );
67+
equal( headers.eq( 1 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
6868
equal( headers.eq( 1 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel has aria-hidden=true" );
6969
equal( headers.eq( 2 ).attr( "tabindex" ), -1, "inactive header has tabindex=-1" );
7070
equal( headers.eq( 2 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected=false" );
71-
equal( headers.eq( 2 ).next().attr( "aria-expanded" ), "false", "inactive tabpanel has aria-expanded=false" );
71+
equal( headers.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
7272
equal( headers.eq( 2 ).next().attr( "aria-hidden" ), "true", "inactive tabpanel has aria-hidden=true" );
7373
});
7474

ui/jquery.ui.accordion.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ $.widget( "ui.accordion", {
102102
this.headers
103103
.removeClass( "ui-accordion-header ui-accordion-header-active ui-helper-reset ui-state-default ui-corner-all ui-state-active ui-state-disabled ui-corner-top" )
104104
.removeAttr( "role" )
105+
.removeAttr( "aria-expanded" )
105106
.removeAttr( "aria-selected" )
106107
.removeAttr( "aria-controls" )
107108
.removeAttr( "tabIndex" )
@@ -116,7 +117,6 @@ $.widget( "ui.accordion", {
116117
contents = this.headers.next()
117118
.css( "display", "" )
118119
.removeAttr( "role" )
119-
.removeAttr( "aria-expanded" )
120120
.removeAttr( "aria-hidden" )
121121
.removeAttr( "aria-labelledby" )
122122
.removeClass( "ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content ui-accordion-content-active ui-state-disabled" )
@@ -293,11 +293,11 @@ $.widget( "ui.accordion", {
293293
.not( this.active )
294294
.attr({
295295
"aria-selected": "false",
296+
"aria-expanded": "false",
296297
tabIndex: -1
297298
})
298299
.next()
299300
.attr({
300-
"aria-expanded": "false",
301301
"aria-hidden": "true"
302302
})
303303
.hide();
@@ -308,11 +308,11 @@ $.widget( "ui.accordion", {
308308
} else {
309309
this.active.attr({
310310
"aria-selected": "true",
311+
"aria-expanded": "true",
311312
tabIndex: 0
312313
})
313314
.next()
314315
.attr({
315-
"aria-expanded": "true",
316316
"aria-hidden": "false"
317317
});
318318
}
@@ -467,15 +467,17 @@ $.widget( "ui.accordion", {
467467
}
468468

469469
toHide.attr({
470-
"aria-expanded": "false",
471470
"aria-hidden": "true"
472471
});
473472
toHide.prev().attr( "aria-selected", "false" );
474473
// if we're switching panels, remove the old header from the tab order
475474
// if we're opening from collapsed state, remove the previous header from the tab order
476475
// if we're collapsing, then keep the collapsing header in the tab order
477476
if ( toShow.length && toHide.length ) {
478-
toHide.prev().attr( "tabIndex", -1 );
477+
toHide.prev().attr({
478+
"tabIndex": -1,
479+
"aria-expanded": "false"
480+
});
479481
} else if ( toShow.length ) {
480482
this.headers.filter(function() {
481483
return $( this ).attr( "tabIndex" ) === 0;
@@ -484,14 +486,12 @@ $.widget( "ui.accordion", {
484486
}
485487

486488
toShow
487-
.attr({
488-
"aria-expanded": "true",
489-
"aria-hidden": "false"
490-
})
489+
.attr( "aria-hidden", "false" )
491490
.prev()
492491
.attr({
493492
"aria-selected": "true",
494-
tabIndex: 0
493+
tabIndex: 0,
494+
"aria-expanded": "true"
495495
});
496496
},
497497

@@ -563,7 +563,6 @@ $.widget( "ui.accordion", {
563563
if ( toHide.length ) {
564564
toHide.parent()[0].className = toHide.parent()[0].className;
565565
}
566-
567566
this._trigger( "activate", null, data );
568567
}
569568
});

0 commit comments

Comments
 (0)