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

Commitb3e4a7e

Browse files
committed
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(cherry picked from commite539bac)
1 parent752b898 commitb3e4a7e

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
@@ -778,10 +778,10 @@ jQuery.each( { focus: "focusin", blur: "focusout" }, function( type, delegateTyp
778778
returntrue;
779779
},
780780

781-
// Suppress native focus or bluras it's already being fired
782-
//in leverageNative.
783-
_default:function(){
784-
returntrue;
781+
// Suppress native focus or blurif we're currently inside
782+
//a leveraged native-event stack
783+
_default:function(event){
784+
returndataPriv.get(event.target,type);
785785
},
786786

787787
delegateType:delegateType

‎test/unit/event.js

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

3300+
QUnit.test("trigger(focus) works after .on(focus).off(focus) (gh-4867)",function(assert){
3301+
assert.expect(1);
3302+
3303+
varinput=jQuery("<input />");
3304+
3305+
input.appendTo("#qunit-fixture");
3306+
3307+
input
3308+
.on("focus",function(){})
3309+
.off("focus");
3310+
3311+
input.trigger("focus");
3312+
3313+
assert.equal(document.activeElement,input[0],"input has focus");
3314+
});
3315+
33003316
// TODO replace with an adaptation of
33013317
// https://github.com/jquery/jquery/pull/1367/files#diff-a215316abbaabdf71857809e8673ea28R2464
33023318
(function(){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp