Skip to content

Commit 965cb73

Browse files
David Murdochscottgonzalez
David Murdoch
authored andcommitted
Tabs: When adding a new tab with an existing panel, don't move it. Fixes #4578 - adding tab moves targeted panel.
1 parent db3d194 commit 965cb73

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

ui/jquery.ui.tabs.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -775,20 +775,30 @@ if ( $.uiBackCompat !== false ) {
775775
li.addClass( "ui-state-default ui-corner-top" ).data( "destroy.tabs", true );
776776
li.find( "a" ).attr( "aria-controls", id );
777777

778+
var doInsertAfter = index >= this.lis.length;
779+
778780
// try to find an existing element before creating a new one
779781
var panel = this.element.find( "#" + id );
780782
if ( !panel.length ) {
781783
panel = this._createPanel( id );
784+
if ( doInsertAfter ) {
785+
if ( index > 0 ) {
786+
panel.insertAfter( this.panels.eq( -1 ) );
787+
} else {
788+
panel.appendTo( this.element );
789+
}
790+
} else {
791+
panel.insertBefore( this.panels[ index ] );
792+
}
782793
}
783794
panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ).hide();
784795

785-
if ( index >= this.lis.length ) {
796+
if ( doInsertAfter ) {
786797
li.appendTo( this.list );
787-
panel.appendTo( this.list[ 0 ].parentNode );
788798
} else {
789799
li.insertBefore( this.lis[ index ] );
790-
panel.insertBefore( this.panels[ index ] );
791800
}
801+
792802
options.disabled = $.map( options.disabled, function( n ) {
793803
return n >= index ? ++n : n;
794804
});

0 commit comments

Comments
 (0)