Skip to content

Dialog: Add the possibility to set dialog("option", "zIndex", 3999) #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/unit/dialog/dialog_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,36 @@ test("width", function() {
el.remove();
});

test("zIndex", function() {
expect(9);

el = $('<div></div>').dialog( { autoOpen: false } );
equals(dlg().css( 'zIndex' ), 1000, "default zIndex");
el.dialog("open");
equals(dlg().css( 'zIndex' ), $.ui.dialog.maxZ, "default zIndex");
el.remove();

el = $('<div></div>').dialog();
equals(dlg().css( 'zIndex' ), $.ui.dialog.maxZ, "default zIndex");
el.remove();

// The z-index will be 1 higher than requested if 'moveToTop' gets called, such as when 'autoOpen' is true.
newZIndex = $.ui.dialog.maxZ + 2932;
el = $('<div></div>').dialog({zIndex: newZIndex });
equals(dlg().css('zIndex'), newZIndex + 1, "explicit zIndex");
equals( el.dialog( 'option', 'zIndex' ), newZIndex, 'get works for zIndex' );
equals( newZIndex + 1, $.ui.dialog.maxZ, '$.ui.dialog.maxZ is updated to the new value' );

el.dialog('option', 'zIndex', 1748);
equals(dlg().css('zIndex'), 1748, 'explicit zIndex after init');
equals( el.dialog( 'option', 'zIndex' ), 1748 );
el.remove();

// At the moment, an explicit zIndex option lower than $.ui.dialog.maxZ will be ignored since 'open' calls
// 'moveToTop'. Is this the desired behavior?
el = $('<div></div>').dialog({zIndex: 1584 });
equals(dlg().css('zIndex'), $.ui.dialog.maxZ, "explicit zIndex at instantiation below $.ui.dialog.maxZ is ignored");
el.remove();
});

})(jQuery);
19 changes: 19 additions & 0 deletions ui/jquery.ui.dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,25 @@ $.widget("ui.dialog", {
$( ".ui-dialog-title", self.uiDialogTitlebar )
.html( "" + ( value || "&#160;" ) );
break;
case "zIndex":
if ( value > $.ui.dialog.maxZ ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this maxZ should only be set when the dialog is currently displayed

// Increment the 'maxZ' counters when this dialog is currently visible
if ( self.isOpen() ) {
$.ui.dialog.maxZ = value;

if ( self.overlay ) {
$.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ;
$.ui.dialog.maxZ += 1;
}
}

value = $.ui.dialog.maxZ;
}

self.overlay && self.overlay.$el.css( "z-index", value - 1 );
uiDialog.css( "z-index", value );

break;
}

this._super( key, value );
Expand Down