Side navigation
#12868 closed bug (fixed)
Opened November 08, 2012 02:18PM UTC
Closed November 24, 2012 07:54PM UTC
Last modified March 18, 2013 03:37PM UTC
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: |
Description
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.
Attachments (0)
Change History (7)
Changed November 08, 2012 03:27PM UTC by comment:1
component: | unfiled → event |
---|---|
milestone: | None → 1.next |
priority: | undecided → high |
status: | new → open |
Changed November 08, 2012 05:23PM UTC by comment:2
owner: | → dmethvin |
---|---|
status: | open → assigned |
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.
Changed November 24, 2012 07:54PM UTC by comment:3
resolution: | → fixed |
---|---|
status: | assigned → closed |
Fix #12868. Use native focus/blur to get event order right.
Changeset: b7ec6ddd45e27b54f3e094172b7eeb6949d4f71b
Changed March 18, 2013 08:24AM UTC by comment:5
@dmethvin
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.
Changed March 18, 2013 08:28AM UTC by comment:6
demo: http://jsfiddle.net/2C8kk/8/
(leave alone firefox)
Changed March 18, 2013 03:37PM UTC by comment:7
@yiminghe, please open a new ticket for a new problem, you can reference this ticket.
Thanks for the test case.