Skip to content

Commit 7b506cf

Browse files
committed
Fixed accordion option active getter and setter. Normalized getter to number, 0-based index.
1 parent 57e3595 commit 7b506cf

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

tests/unit/accordion/accordion_options.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,20 @@ test("{ active: false }", function() {
3838
});
3939

4040
test("{ active: Number }", function() {
41-
ok(false, 'missing test - untested code is broken code');
41+
expect(4);
42+
$("#list1").accordion({
43+
active: 0
44+
});
45+
equals( $("#list1").accordion('option', 'active'), 0);
46+
47+
$("#list1").accordion('option', 'active', 1);
48+
equals( $("#list1").accordion('option', 'active'), 1);
49+
50+
$('.ui-accordion-header:eq(2)', '#list1').click();
51+
equals( $("#list1").accordion('option', 'active'), 2);
52+
53+
$("#list1").accordion('activate', 0);
54+
equals( $("#list1").accordion('option', 'active'), 0);
4255
});
4356

4457
test("{ animated: false }, default", function() {

ui/ui.accordion.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ $.widget("ui.accordion", {
153153

154154
$.widget.prototype._setData.apply(this, arguments);
155155

156+
if (key == "active") {
157+
this.activate(value);
158+
}
156159
if (key == "icons") {
157160
this._destroyIcons();
158161
if (value) {
@@ -230,6 +233,7 @@ $.widget("ui.accordion", {
230233
},
231234

232235
activate: function(index) {
236+
this.options.active = index;
233237
// call clickHandler with custom event
234238
var active = this._findActive(index)[0];
235239
this._clickHandler({ target: active }, active);
@@ -273,6 +277,8 @@ $.widget("ui.accordion", {
273277
// get the click target
274278
var clicked = $(event.currentTarget || target);
275279
var clickedIsActive = clicked[0] == this.active[0];
280+
281+
o.active = $('.ui-accordion-header', this.element).index(clicked);
276282

277283
// if animations are still active, or the active header is the target, ignore click
278284
if (this.running || (!o.collapsible && clickedIsActive)) {

0 commit comments

Comments
 (0)