Skip to content

Commit 8724092

Browse files
committed
Dialog: Don't use ._on() for modal event handlers. Fixes #9048 - Dialog: broken focusin event handler when beforeclose event of a modal opens another modal.
1 parent 9c6b8f8 commit 8724092

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

tests/unit/dialog/dialog_core.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,17 @@ asyncTest( "Prevent tabbing out of dialogs", function() {
147147
});
148148
});
149149

150+
asyncTest( "#9048: multiple modal dialogs opened and closed in different order", function() {
151+
expect( 1 );
152+
$( "#dialog1, #dialog2" ).dialog({ autoOpen: false, modal:true });
153+
$( "#dialog1" ).dialog( "open" );
154+
$( "#dialog2" ).dialog( "open" );
155+
$( "#dialog1" ).dialog( "close" );
156+
setTimeout(function() {
157+
$( "#dialog2" ).dialog( "close" );
158+
$( "#favorite-animal" ).focus();
159+
ok( true, "event handlers cleaned up (no errors thrown)" );
160+
start();
161+
});
162+
});
150163
})(jQuery);

ui/jquery.ui.dialog.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -678,16 +678,14 @@ $.widget( "ui.dialog", {
678678
this._delay(function() {
679679
// Handle .dialog().dialog("close") (#4065)
680680
if ( $.ui.dialog.overlayInstances ) {
681-
this._on( this.document, {
682-
focusin: function( event ) {
683-
if ( !$( event.target ).closest(".ui-dialog").length &&
684-
// TODO: Remove hack when datepicker implements
685-
// the .ui-front logic (#8989)
686-
!$( event.target ).closest(".ui-datepicker").length ) {
687-
event.preventDefault();
688-
$(".ui-dialog:visible:last .ui-dialog-content")
689-
.data("ui-dialog")._focusTabbable();
690-
}
681+
this.document.bind( "focusin.dialog", function( event ) {
682+
if ( !$( event.target ).closest(".ui-dialog").length &&
683+
// TODO: Remove hack when datepicker implements
684+
// the .ui-front logic (#8989)
685+
!$( event.target ).closest(".ui-datepicker").length ) {
686+
event.preventDefault();
687+
$(".ui-dialog:visible:last .ui-dialog-content")
688+
.data("ui-dialog")._focusTabbable();
691689
}
692690
});
693691
}
@@ -712,7 +710,7 @@ $.widget( "ui.dialog", {
712710
$.ui.dialog.overlayInstances--;
713711

714712
if ( !$.ui.dialog.overlayInstances ) {
715-
this._off( this.document, "focusin" );
713+
this.document.unbind( "focusin.dialog" );
716714
}
717715
this.overlay.remove();
718716
this.overlay = null;

0 commit comments

Comments
 (0)