Event: Don't break focus triggering after .on(focus).off(focus)#4885
Merged
Conversation
The `_default` function in the special event settings for focus/blur has always returned `true` since jquerygh-4813 as the event was already being fired from `leverageNative`. However, that only works if there's an active handler on that element; this made a quick consecutive call: ```js elem.on( "focus", function() {} ).off( "focus" ); ``` make subsequent `.trigger( "focus" )` calls to not do any triggering. The solution, already used in a similar `_default` method for the `click` event, is to check for the `dataPriv` entry on the element for the focus event (similarly for blur). Fixes jquerygh-4867
mgol
added a commit
to mgol/jquery
that referenced
this pull request
May 10, 2021
The `_default` function in the special event settings for focus/blur has always returned `true` since jquerygh-4813 as the event was already being fired from `leverageNative`. However, that only works if there's an active handler on that element; this made a quick consecutive call: ```js elem.on( "focus", function() {} ).off( "focus" ); ``` make subsequent `.trigger( "focus" )` calls to not do any triggering. The solution, already used in a similar `_default` method for the `click` event, is to check for the `dataPriv` entry on the element for the focus event (similarly for blur). Fixes jquerygh-4867 Closes jquerygh-4885 (cherry picked from commit e539bac)
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
_defaultfunction in the special event settings for focus/blur hasalways returned
truesince gh-4813 as the event was already being firedfrom
leverageNative. However, that only works if there's an active handleron that element; this made a quick consecutive call:
make subsequent
.trigger( "focus" )calls to not do any triggering.The solution, already used in a similar
_defaultmethod for theclickevent,is to check for the
dataPriventry on the element for the focus event(similarly for blur).
Fixes gh-4867
+10 bytes
Checklist
If needed, a docs issue/PR was created at https://github.com/jquery/api.jquery.com