mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Dialog: Search the correct document for focus trapping. Fixes #9439 - Dialog: Context is not respected for modals.
This commit is contained in:
parent
92d5421395
commit
c9815f13b4
@ -63,21 +63,21 @@ test("destroy", function() {
|
||||
// Don't throw errors when destroying a never opened modal dialog (#9004)
|
||||
$( "#dialog1" ).dialog({ autoOpen: false, modal: true }).dialog( "destroy" );
|
||||
equal( $( ".ui-widget-overlay" ).length, 0, "overlay does not exist" );
|
||||
equal( $.ui.dialog.overlayInstances, 0, "overlayInstances equals the number of open overlays");
|
||||
equal( $( document ).data( "ui-dialog-overlays" ), undefined, "ui-dialog-overlays equals the number of open overlays");
|
||||
|
||||
element = $( "#dialog1" ).dialog({ modal: true }),
|
||||
element2 = $( "#dialog2" ).dialog({ modal: true });
|
||||
equal( $( ".ui-widget-overlay" ).length, 2, "overlays created when dialogs are open" );
|
||||
equal( $.ui.dialog.overlayInstances, 2, "overlayInstances equals the number of open overlays" );
|
||||
equal( $( document ).data( "ui-dialog-overlays" ), 2, "ui-dialog-overlays equals the number of open overlays" );
|
||||
element.dialog( "close" );
|
||||
equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after closing one dialog" );
|
||||
equal( $.ui.dialog.overlayInstances, 1, "overlayInstances equals the number of open overlays" );
|
||||
equal( $( document ).data( "ui-dialog-overlays" ), 1, "ui-dialog-overlays equals the number of open overlays" );
|
||||
element.dialog( "destroy" );
|
||||
equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after destroying one dialog" );
|
||||
equal( $.ui.dialog.overlayInstances, 1, "overlayInstances equals the number of open overlays" );
|
||||
equal( $( document ).data( "ui-dialog-overlays" ), 1, "ui-dialog-overlays equals the number of open overlays" );
|
||||
element2.dialog( "destroy" );
|
||||
equal( $( ".ui-widget-overlay" ).length, 0, "overlays removed when all dialogs are destoryed" );
|
||||
equal( $.ui.dialog.overlayInstances, 0, "overlayInstances equals the number of open overlays" );
|
||||
equal( $( document ).data( "ui-dialog-overlays" ), undefined, "ui-dialog-overlays equals the number of open overlays" );
|
||||
});
|
||||
|
||||
asyncTest("#9000: Dialog leaves broken event handler after close/destroy in certain cases", function() {
|
||||
|
53
ui/jquery.ui.dialog.js
vendored
53
ui/jquery.ui.dialog.js
vendored
@ -724,22 +724,27 @@ $.widget( "ui.dialog", {
|
||||
return;
|
||||
}
|
||||
|
||||
var that = this,
|
||||
widgetFullName = this.widgetFullName;
|
||||
if ( !$.ui.dialog.overlayInstances ) {
|
||||
// Prevent use of anchors and inputs.
|
||||
// We use a delay in case the overlay is created from an
|
||||
// event that we're going to be cancelling. (#2804)
|
||||
this._delay(function() {
|
||||
// Handle .dialog().dialog("close") (#4065)
|
||||
if ( $.ui.dialog.overlayInstances ) {
|
||||
this.document.bind( "focusin.dialog", function( event ) {
|
||||
if ( !that._allowInteraction( event ) ) {
|
||||
event.preventDefault();
|
||||
$(".ui-dialog:visible:last .ui-dialog-content")
|
||||
.data( widgetFullName )._focusTabbable();
|
||||
}
|
||||
});
|
||||
// We use a delay in case the overlay is created from an
|
||||
// event that we're going to be cancelling (#2804)
|
||||
var isOpening = true;
|
||||
this._delay(function() {
|
||||
isOpening = false;
|
||||
});
|
||||
|
||||
if ( !this.document.data( "ui-dialog-overlays" ) ) {
|
||||
|
||||
// Prevent use of anchors and inputs
|
||||
this._on( this.document, {
|
||||
focusin: function( event ) {
|
||||
if ( isOpening ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !this._allowInteraction( event ) ) {
|
||||
event.preventDefault();
|
||||
this.document.find( ".ui-dialog:visible:last .ui-dialog-content" )
|
||||
.data( this.widgetFullName )._focusTabbable();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -750,7 +755,8 @@ $.widget( "ui.dialog", {
|
||||
this._on( this.overlay, {
|
||||
mousedown: "_keepFocus"
|
||||
});
|
||||
$.ui.dialog.overlayInstances++;
|
||||
this.document.data( "ui-dialog-overlays",
|
||||
(this.document.data( "ui-dialog-overlays" ) || 0) + 1 );
|
||||
},
|
||||
|
||||
_destroyOverlay: function() {
|
||||
@ -759,17 +765,20 @@ $.widget( "ui.dialog", {
|
||||
}
|
||||
|
||||
if ( this.overlay ) {
|
||||
$.ui.dialog.overlayInstances--;
|
||||
var overlays = this.document.data( "ui-dialog-overlays" ) - 1;
|
||||
|
||||
if ( !$.ui.dialog.overlayInstances ) {
|
||||
this.document.unbind( "focusin.dialog" );
|
||||
if ( !overlays ) {
|
||||
this.document
|
||||
.off( "focusin" )
|
||||
.removeData( "ui-dialog-overlays" );
|
||||
} else {
|
||||
this.document.data( "ui-dialog-overlays", overlays );
|
||||
}
|
||||
|
||||
this.overlay.remove();
|
||||
this.overlay = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$.ui.dialog.overlayInstances = 0;
|
||||
|
||||
}( jQuery ) );
|
||||
|
Loading…
Reference in New Issue
Block a user