Skip to content

Commit 714a77f

Browse files
committed
Accordion: Properly handle collapsible: false and active: false by changing active to 0.
1 parent 39cf7d5 commit 714a77f

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

tests/unit/accordion/accordion_options.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ test( "{ active: false }", function() {
1717
equals( ac.find( ".ui-accordion-header.ui-state-active" ).size(), 0, "no headers selected" );
1818
equals( ac.accordion( "option", "active" ), false );
1919

20-
// TODO: fix active: false when not collapsible
21-
// ac.accordion( "option", "collapsible", false );
22-
// state( ac, 1, 0, 0 );
23-
// equals( ac.accordion( "option", "active" ), 0 );
24-
//
25-
// ac.accordion( "destroy" );
26-
// ac.accordion({
27-
// active: false
28-
// });
29-
// state( ac, 1, 0, 0 );
30-
// strictEqual( ac.accordion( "option", "active" ), 0 );
20+
ac.accordion( "option", "collapsible", false );
21+
state( ac, 1, 0, 0 );
22+
equals( ac.accordion( "option", "active" ), 0 );
23+
24+
ac.accordion( "destroy" );
25+
ac.accordion({
26+
active: false
27+
});
28+
state( ac, 1, 0, 0 );
29+
strictEqual( ac.accordion( "option", "active" ), 0 );
3130
});
3231

3332
test( "{ active: Number }", function() {

ui/jquery.ui.accordion.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ $.widget( "ui.accordion", {
4444
self.headers.next()
4545
.addClass( "ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" );
4646

47+
// don't allow collapsible: false and active: false
48+
if ( !options.collapsible && options.active === false ) {
49+
options.active = 0;
50+
}
4751
self.active = self._findActive( options.active )
4852
.addClass( "ui-state-default ui-state-active" )
4953
.toggleClass( "ui-corner-all" )
@@ -149,12 +153,18 @@ $.widget( "ui.accordion", {
149153

150154
this._super( "_setOption", key, value );
151155

156+
// setting collapsible: false while collapsed; open first panel
157+
if ( key === "collapsible" && !value && this.options.active === false ) {
158+
this._activate( 0 );
159+
}
160+
152161
if ( key === "icons" ) {
153162
this._destroyIcons();
154163
if ( value ) {
155164
this._createIcons();
156165
}
157166
}
167+
158168
// #5332 - opacity doesn't cascade to positioned elements in IE
159169
// so we need to add the disabled class to the headers and panels
160170
if ( key === "disabled" ) {

0 commit comments

Comments
 (0)