Skip to content
Permalink
Browse files

Tabs: Properly handle switching from active: false.

  • Loading branch information...
scottgonzalez committed Apr 4, 2011
1 parent fc52912 commit e19d8261c136e6c0b40e08b5bede24467b3dcc0f
Showing with 26 additions and 5 deletions.
  1. +23 −2 tests/unit/tabs/tabs_events.js
  2. +3 −3 ui/jquery.ui.tabs.js
@@ -3,7 +3,7 @@
module( "tabs: events" );

test( "beforeActivate", function() {
expect( 26 );
expect( 38 );

var element = $( "#tabs1" ).tabs({
// TODO: should be false
@@ -13,7 +13,9 @@ test( "beforeActivate", function() {
tabs = element.find( ".ui-tabs-nav a" ),
panels = element.find( ".ui-tabs-panel" );

// from collapsed
element.one( "tabsbeforeactivate", function( event, ui ) {
ok( !( "originalEvent" in event ) );
equals( ui.oldTab.size(), 0 );
equals( ui.oldPanel.size(), 0 );
equals( ui.newTab.size(), 1 );
@@ -25,7 +27,9 @@ test( "beforeActivate", function() {
element.tabs( "option", "active", 0 );
tabs_state( element, 1, 0, 0 );

// switching tabs
element.one( "tabsbeforeactivate", function( event, ui ) {
equals( event.originalEvent.type, "click" );
equals( ui.oldTab.size(), 1 );
strictEqual( ui.oldTab[ 0 ], tabs[ 0 ] );
equals( ui.oldPanel.size(), 1 );
@@ -36,10 +40,12 @@ test( "beforeActivate", function() {
strictEqual( ui.newPanel[ 0 ], panels[ 1 ] );
tabs_state( element, 1, 0, 0 );
});
element.tabs( "option", "active", 1 );
tabs.eq( 1 ).click();
tabs_state( element, 0, 1, 0 );

// collapsing
element.one( "tabsbeforeactivate", function( event, ui ) {
ok( !( "originalEvent" in event ) );
equals( ui.oldTab.size(), 1 );
strictEqual( ui.oldTab[ 0 ], tabs[ 1 ] );
equals( ui.oldPanel.size(), 1 );
@@ -50,6 +56,21 @@ test( "beforeActivate", function() {
});
element.tabs( "option", "active", false );
tabs_state( element, 0, 0, 0 );

// prevent activation
element.one( "tabsbeforeactivate", function( event, ui ) {
ok( !( "originalEvent" in event ) );
equals( ui.oldTab.size(), 0 );
equals( ui.oldPanel.size(), 0 );
equals( ui.newTab.size(), 1 );
strictEqual( ui.newTab[ 0 ], tabs[ 1 ] );
equals( ui.newPanel.size(), 1 );
strictEqual( ui.newPanel[ 0 ], panels[ 1 ] );
event.preventDefault();
tabs_state( element, 0, 0, 0 );
});
element.tabs( "option", "active", 1 );
tabs_state( element, 0, 0, 0 );
});

test('beforeload', function() {
@@ -364,7 +364,7 @@ $.widget( "ui.tabs", {

options.active = collapsing ? false : that.anchors.index( clicked );

that.active = clicked;
that.active = clickedIsActive ? $() : clicked;
if ( that.xhr ) {
that.xhr.abort();
}
@@ -422,12 +422,12 @@ $.widget( "ui.tabs", {
var active = this._findActive( index )[ 0 ];

// trying to activate the already active panel
if ( this.active && active === this.active[ 0 ] ) {
if ( active === this.active[ 0 ] ) {
return;
}

// trying to collapse, simulate a click on the current active header
active = active || this.active;
active = active || this.active[ 0 ];

this._eventHandler({
target: active,

0 comments on commit e19d826

Please sign in to comment.
You can’t perform that action at this time.