aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2020-12-07 20:28:44 +0100
committerMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2020-12-07 21:06:44 +0100
commit2fadbc0a9839893f434cfca42587593c8794375d (patch)
tree50ac607451601ccdc7f15668ff7b47bfa0b12626 /src
parent07829a166439128469ea342fb1b6005b053929f7 (diff)
downloadjquery-2fadbc0a9839893f434cfca42587593c8794375d.tar.gz
jquery-2fadbc0a9839893f434cfca42587593c8794375d.zip
Event: Make focus re-triggering not focus the original element back
If during a focus handler another focus event is triggered: ```js elem1.on( "focus", function() { elem2.trigger( "focus" ); } ); ``` due to their synchronous nature everywhere outside of IE the hack added in gh-4279 to leverage native events causes the native `.focus()` method to be called last for the initial element, making it steal the focus back. Since the native method is already being called in `leverageNative`, we can skip that final call. This aligns with changes to the `_default` method for the `click` event that were added when `leverageNative` was introduced there. A side effect of this change is that now `focusin` will only propagate to the document for the last focused element. This is a change in behavior but it also aligns us better with how this works with native methods. Fixes gh-4382 Closes gh-4813 Ref gh-4279 (cherry picked from commit dbcffb396c2db61ff96edc4162602e850797d61f)
Diffstat (limited to 'src')
-rw-r--r--src/event.js6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/event.js b/src/event.js
index 5e2cee0e5..a954400a3 100644
--- a/src/event.js
+++ b/src/event.js
@@ -778,6 +778,12 @@ jQuery.each( { focus: "focusin", blur: "focusout" }, function( type, delegateTyp
return true;
},
+ // Suppress native focus or blur as it's already being fired
+ // in leverageNative.
+ _default: function() {
+ return true;
+ },
+
delegateType: delegateType
};
} );