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

Commitdbcffb3

Browse files
authored
Event: Make focus re-triggering not focus the original element back
If during a focus handler another focus event is triggered:```jselem1.on( "focus", function() {elem2.trigger( "focus" );} );```due to their synchronous nature everywhere outside of IE the hack added ingh-4279 to leverage native events causes the native `.focus()` method to becalled last for the initial element, making it steal the focus back. Sincethe native method is already being called in `leverageNative`, we can skip thatfinal call.This aligns with changes to the `_default` method for the `click` event thatwere added when `leverageNative` was introduced there.A side effect of this change is that now `focusin` will only propagate to thedocument for the last focused element. This is a change in behavior but it alsoaligns us better with how this works with native methods.Fixesgh-4382Closesgh-4813Refgh-4279
1 parent6984d17 commitdbcffb3

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

‎src/event.js

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

749+
// Suppress native focus or blur as it's already being fired
750+
// in leverageNative.
751+
_default:function(){
752+
returntrue;
753+
},
754+
749755
delegateType:delegateType
750756
};
751757
});

‎test/unit/event.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,6 +3291,40 @@ QUnit.test( "native-backed events preserve trigger data (gh-1741, gh-4139)", fun
32913291
},50);
32923292
});
32933293

3294+
QUnit.test("focus change during a focus handler (gh-4382)",function(assert){
3295+
assert.expect(2);
3296+
3297+
vardone=assert.async(),
3298+
select=jQuery("<select><option selected='selected'>A</option></select>"),
3299+
button=jQuery("<button>Focus target</button>");
3300+
3301+
jQuery("#qunit-fixture")
3302+
.append(select)
3303+
.append(button);
3304+
3305+
select.on("focus",function(){
3306+
button.trigger("focus");
3307+
});
3308+
3309+
jQuery(document).on("focusin.focusTests",function(ev){
3310+
// Support: IE 11+
3311+
// In IE focus is async so focusin on document is fired multiple times,
3312+
// for each of the elements. In other browsers it's fired just once, for
3313+
// the last one.
3314+
if(ev.target===button[0]){
3315+
assert.ok(true,"focusin propagated to document from the button");
3316+
}
3317+
});
3318+
3319+
select.trigger("focus");
3320+
3321+
setTimeout(function(){
3322+
assert.strictEqual(document.activeElement,button[0],"Focus redirect worked");
3323+
jQuery(document).off(".focusTests");
3324+
done();
3325+
});
3326+
});
3327+
32943328
// TODO replace with an adaptation of
32953329
// https://github.com/jquery/jquery/pull/1367/files#diff-a215316abbaabdf71857809e8673ea28R2464
32963330
(function(){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp