Tabs: Prevent default action of clicks even when disabled. Fixes #9413 - Tabs: Disabled tabs are still clickable.

This commit is contained in:
Scott González 2013-07-03 14:38:35 -04:00
parent 7da828375a
commit 4148acfa9a
2 changed files with 14 additions and 7 deletions

View File

@ -144,10 +144,11 @@ test( "{ collapsible: true }", function() {
}); });
test( "disabled", function() { test( "disabled", function() {
expect( 22 ); expect( 23 );
// fully enabled by default // fully enabled by default
var element = $( "#tabs1" ).tabs(); var event,
element = $( "#tabs1" ).tabs();
disabled( element, false ); disabled( element, false );
ok( !element.tabs( "widget" ).hasClass( "ui-state-disabled" ), "after: wrapper doesn't have ui-state-disabled class" ); ok( !element.tabs( "widget" ).hasClass( "ui-state-disabled" ), "after: wrapper doesn't have ui-state-disabled class" );
@ -178,6 +179,10 @@ test( "disabled", function() {
ok( !element.tabs( "widget" ).hasClass( "ui-tabs-disabled" ), "after: wrapper doesn't have ui-tabs-disabled class" ); ok( !element.tabs( "widget" ).hasClass( "ui-tabs-disabled" ), "after: wrapper doesn't have ui-tabs-disabled class" );
ok( !element.tabs( "widget" ).attr( "aria-disabled" ), "after: wrapper doesn't have aria-disabled attr" ); ok( !element.tabs( "widget" ).attr( "aria-disabled" ), "after: wrapper doesn't have aria-disabled attr" );
event = $.Event( "click" );
element.find( ".ui-tabs-anchor" ).eq( 0 ).trigger( event );
ok( event.isDefaultPrevented(), "click is prevented for disabled tab" );
// enable all tabs // enable all tabs
element.tabs( "option", "disabled", [] ); element.tabs( "option", "disabled", [] );
disabled( element, false ); disabled( element, false );

12
ui/jquery.ui.tabs.js vendored
View File

@ -477,11 +477,7 @@ $.widget( "ui.tabs", {
}, },
_setupEvents: function( event ) { _setupEvents: function( event ) {
var events = { var events = {};
click: function( event ) {
event.preventDefault();
}
};
if ( event ) { if ( event ) {
$.each( event.split(" "), function( index, eventName ) { $.each( event.split(" "), function( index, eventName ) {
events[ eventName ] = "_eventHandler"; events[ eventName ] = "_eventHandler";
@ -489,6 +485,12 @@ $.widget( "ui.tabs", {
} }
this._off( this.anchors.add( this.tabs ).add( this.panels ) ); this._off( this.anchors.add( this.tabs ).add( this.panels ) );
// Always prevent the default action, even when disabled
this._on( true, this.anchors, {
click: function( event ) {
event.preventDefault();
}
});
this._on( this.anchors, events ); this._on( this.anchors, events );
this._on( this.tabs, { keydown: "_tabKeydown" } ); this._on( this.tabs, { keydown: "_tabKeydown" } );
this._on( this.panels, { keydown: "_panelKeydown" } ); this._on( this.panels, { keydown: "_panelKeydown" } );