Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite539bac

Browse files
authored
Event: Don't break focus triggering after.on(focus).off(focus)
The `_default` function in the special event settings for focus/blur hasalways returned `true` sincegh-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:```jselem.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).Fixesgh-4867Closesgh-4885
1 parenta702746 commite539bac

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

‎src/event.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -746,10 +746,10 @@ jQuery.each( { focus: "focusin", blur: "focusout" }, function( type, delegateTyp
746746
returntrue;
747747
},
748748

749-
// Suppress native focus or bluras it's already being fired
750-
//in leverageNative.
751-
_default:function(){
752-
returntrue;
749+
// Suppress native focus or blurif we're currently inside
750+
//a leveraged native-event stack
751+
_default:function(event){
752+
returndataPriv.get(event.target,type);
753753
},
754754

755755
delegateType:delegateType

‎test/unit/event.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3325,6 +3325,22 @@ QUnit.test( "focus change during a focus handler (gh-4382)", function( assert )
33253325
});
33263326
});
33273327

3328+
QUnit.test("trigger(focus) works after .on(focus).off(focus) (gh-4867)",function(assert){
3329+
assert.expect(1);
3330+
3331+
varinput=jQuery("<input />");
3332+
3333+
input.appendTo("#qunit-fixture");
3334+
3335+
input
3336+
.on("focus",function(){})
3337+
.off("focus");
3338+
3339+
input.trigger("focus");
3340+
3341+
assert.equal(document.activeElement,input[0],"input has focus");
3342+
});
3343+
33283344
// TODO replace with an adaptation of
33293345
// https://github.com/jquery/jquery/pull/1367/files#diff-a215316abbaabdf71857809e8673ea28R2464
33303346
(function(){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp