Skip to content

Dialog: Fix shared event handler for modal dialogs #1817

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
Closed
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
29 changes: 14 additions & 15 deletions ui/widgets/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ $.widget( "ui.dialog", {
that._trigger( "focus" );
} );

// Track the dialog immediately upon openening in case a focus event
// Track the dialog immediately upon opening in case a focus event
// somehow occurs outside of the dialog before an element inside the
// dialog is focused (#10152)
this._makeFocusTarget();
Expand Down Expand Up @@ -863,20 +863,19 @@ $.widget( "ui.dialog", {
if ( !this.document.data( "ui-dialog-overlays" ) ) {

// Prevent use of anchors and inputs
// Using _on() for an event handler shared across many instances is
// safe because the dialogs stack and must be closed in reverse order
this._on( this.document, {
focusin: function( event ) {
if ( isOpening ) {
return;
}

if ( !this._allowInteraction( event ) ) {
event.preventDefault();
this._trackingInstances()[ 0 ]._focusTabbable();
}
// This doesn't use `_on()` because it is a shared event handler
// across all open modal dialogs.
this.document.on( "focusin.ui-dialog", function( event ) {
if ( isOpening ) {
return;
}
} );

var instance = this._trackingInstances()[ 0 ];
if ( !instance._allowInteraction( event ) ) {
event.preventDefault();
instance._focusTabbable();
}
}.bind( this ) );
}

this.overlay = $( "<div>" )
Expand All @@ -899,7 +898,7 @@ $.widget( "ui.dialog", {
var overlays = this.document.data( "ui-dialog-overlays" ) - 1;

if ( !overlays ) {
this._off( this.document, "focusin" );
this.document.off( "focusin.ui-dialog" );
this.document.removeData( "ui-dialog-overlays" );
} else {
this.document.data( "ui-dialog-overlays", overlays );
Expand Down