Skip to content

Commit 0e7769c

Browse files
petersendiditscottgonzalez
authored andcommitted
Tabs: enable/disable handle when current state already matches, fix error when disabled = true and enable gets called
1 parent abe4c37 commit 0e7769c

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

tests/unit/tabs/tabs_methods.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test('destroy', function() {
1818
});
1919

2020
test('enable', function() {
21-
expect(8);
21+
expect(12);
2222

2323
el = $('#tabs1').tabs({ disabled: [ 0, 1 ] });
2424
el.tabs("enable", 1);
@@ -31,6 +31,18 @@ test('enable', function() {
3131
ok( !$('li.ui-state-disabled', el).length, 'enable all');
3232
same(el.tabs('option', 'disabled'), false, 'update property');
3333

34+
// enable one tab
35+
el.tabs({ disabled: true });
36+
el.tabs("enable", 1);
37+
ok( $('li:eq(1)', el).is(':not(.ui-state-disabled)'), 'remove class from li');
38+
same(el.tabs('option', 'disabled'), [ 0, 2 ], 'update property');
39+
40+
// all tabs already enabled
41+
el.tabs({ disabled: false });
42+
el.tabs("enable", 1);
43+
ok( !$('li.ui-state-disabled', el).length, 'enable all');
44+
same(el.tabs('option', 'disabled'), false, 'update property');
45+
3446
el.tabs('destroy');
3547
// enable all tabs one by one
3648
el.tabs({ disabled: [ 1, 2 ] });
@@ -43,7 +55,7 @@ test('enable', function() {
4355
});
4456

4557
test('disable', function() {
46-
expect(12);
58+
expect(14);
4759

4860
// normal
4961
el = $('#tabs1').tabs();
@@ -61,6 +73,12 @@ test('disable', function() {
6173
same( $('li.ui-state-disabled', el).length, 3, 'disable all');
6274
same(el.tabs('option', 'disabled'), true, 'set to true');
6375

76+
// all tabs already disabled
77+
el.tabs({ disabled: true });
78+
el.tabs("disable", 1);
79+
ok( $('li.ui-state-disabled', el).length, 'disable all');
80+
same(el.tabs('option', 'disabled'), true, 'set to true');
81+
6482
el.tabs("destroy");
6583
// disable all tabs one by one
6684
el.tabs();

ui/jquery.ui.tabs.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ $.widget( "ui.tabs", {
513513

514514
enable: function( index ) {
515515
var disabled = this.options.disabled;
516+
if ( disabled === false ) {
517+
return;
518+
}
516519

517520
if ( index === undefined ) {
518521
disabled = false;
@@ -523,14 +526,19 @@ $.widget( "ui.tabs", {
523526
return num !== index ? num : null;
524527
});
525528
} else {
526-
disabled = [ index ];
529+
disabled = $.map( this.lis, function( li, num ) {
530+
return num !== index ? num : null;
531+
});
527532
}
528533
}
529534
this._setupDisabled( disabled );
530535
},
531536

532537
disable: function( index ) {
533538
var disabled = this.options.disabled;
539+
if ( disabled === true ) {
540+
return;
541+
}
534542

535543
if ( index === undefined ) {
536544
disabled = true;

0 commit comments

Comments
 (0)