Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#12868 closed bug (fixed)

jQuery 1.8.2 $.fn.focus triggers events in incorrect order as compared with Javascript focus calls.

Reported by: abhishekdev Owned by: dmethvin
Priority: high Milestone: 1.next
Component: event Version: 1.8.2
Keywords: Cc:
Blocked by: Blocking:


jQuery 1.8.2 focus method triggers blur handler on the document.activeElement after calling focus handler on the new target element.

The issue can be reproduced on the demo page here http://jsbin.com/welcome/45914/. More details have been added as noted to the demo

The issue is regression from v1.6.4. I could reproduce the issue on Firefox 16, Safari 6, Chrome 22.

Change History (7)

comment:1 Changed 10 years ago by timmywil

Component: unfiledevent
Milestone: None1.next
Priority: undecidedhigh
Status: newopen

Thanks for the test case.

comment:2 Changed 10 years ago by dmethvin

Owner: set to dmethvin
Status: openassigned

This is a result of the way .trigger() works; #3827 has the same cause. Focus in particular is problematic because the native DOM .focus() method does not call any handlers if the element is already focused, but there is jQuery code that expects focus handlers to *always* be called as they are today. So we can't just call the native method and be done with it.

Since I have #3827 already I'll take this one as well, but I'm not sure we can make it better. Perhaps differently quirked, but not necessarily better and certainly more complex. For example we can insert a sentinel event handler on the focus event, run the DOM focus method, and see if it fires; if not we would manually trigger any focus/focusin events.

comment:3 Changed 10 years ago by Dave Methvin

Resolution: fixed
Status: assignedclosed

Fix #12868. Use native focus/blur to get event order right.

Changeset: b7ec6ddd45e27b54f3e094172b7eeb6949d4f71b

comment:4 Changed 10 years ago by dmethvin

#12981 is a duplicate of this ticket.

comment:5 Changed 10 years ago by yiminghe


Now focus and focusin listeners are executed in an inconsistent order when trigger('focus').

If element does not has focus, then focusin listeners are executed first (which is right by calling native focus).

Else if element is focused, then focus listners are executed first and focusin listeners are executed second by bubbling. (which is wrong by bubbling, i think).

Maybe you should execute focusin listeners first in trigger() as a special case (which needs a lot of code change and perfect for focus event) or simple make focus event noBubble.

comment:6 Changed 10 years ago by yiminghe

demo: http://jsfiddle.net/2C8kk/8/

(leave alone firefox)

comment:7 Changed 10 years ago by dmethvin

@yiminghe, please open a new ticket for a new problem, you can reference this ticket.

Note: See TracTickets for help on using tickets.