Skip to content

Commit 5708046

Browse files
committed
Dialog: Fix shared event handler for modal dialogs
The old logic worked when all widgets of the same type used the same event namespace. However, now that each instance has its own namespace, we cannot use `_on()` for shared event handlers. Fixes #15182 Closes gh-1817
1 parent 809f29e commit 5708046

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

ui/widgets/dialog.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ $.widget( "ui.dialog", {
289289
that._trigger( "focus" );
290290
} );
291291

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

865865
// Prevent use of anchors and inputs
866-
// Using _on() for an event handler shared across many instances is
867-
// safe because the dialogs stack and must be closed in reverse order
868-
this._on( this.document, {
869-
focusin: function( event ) {
870-
if ( isOpening ) {
871-
return;
872-
}
873-
874-
if ( !this._allowInteraction( event ) ) {
875-
event.preventDefault();
876-
this._trackingInstances()[ 0 ]._focusTabbable();
877-
}
866+
// This doesn't use `_on()` because it is a shared event handler
867+
// across all open modal dialogs.
868+
this.document.on( "focusin.ui-dialog", function( event ) {
869+
if ( isOpening ) {
870+
return;
878871
}
879-
} );
872+
873+
var instance = this._trackingInstances()[ 0 ];
874+
if ( !instance._allowInteraction( event ) ) {
875+
event.preventDefault();
876+
instance._focusTabbable();
877+
}
878+
}.bind( this ) );
880879
}
881880

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

901900
if ( !overlays ) {
902-
this._off( this.document, "focusin" );
901+
this.document.off( "focusin.ui-dialog" );
903902
this.document.removeData( "ui-dialog-overlays" );
904903
} else {
905904
this.document.data( "ui-dialog-overlays", overlays );

0 commit comments

Comments
 (0)