Skip to content

Commit d099e3a

Browse files
committed
Accordion: Handle negative values for active option on init.
1 parent 714a77f commit d099e3a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

tests/unit/accordion/accordion_options.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ test( "{ active: Number }", function() {
5151

5252
if ( $.uiBackCompat === false ) {
5353
test( "{ active: -Number }", function() {
54-
// TODO: fix initializing with negative value
5554
var ac = $( "#list1" ).accordion({
56-
// active: -1
55+
active: -1
5756
});
58-
// equals( ac.accordion( "option", "active" ), 2 );
59-
// state( ac, 0, 0, 1 );
57+
equals( ac.accordion( "option", "active" ), 2 );
58+
state( ac, 0, 0, 1 );
6059

6160
ac.accordion( "option", "active", -2 );
6261
equals( ac.accordion( "option", "active" ), 1 );

ui/jquery.ui.accordion.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ $.widget( "ui.accordion", {
4848
if ( !options.collapsible && options.active === false ) {
4949
options.active = 0;
5050
}
51+
// handle negative values
52+
if ( options.active < 0 ) {
53+
options.active += this.headers.length;
54+
}
5155
self.active = self._findActive( options.active )
5256
.addClass( "ui-state-default ui-state-active" )
5357
.toggleClass( "ui-corner-all" )

0 commit comments

Comments
 (0)