Skip to main content

Bug Tracker

Side navigation

#1486 closed bug (fixed)

Opened August 14, 2007 08:05PM UTC

Closed December 08, 2007 02:55AM UTC

Last modified February 21, 2013 10:23AM UTC

Triggering focus to hidden elements does not work in IE

Reported by: himynameiznate Owned by: brandon
Priority: major Milestone: 1.2.2
Component: event Version: 1.1.3
Keywords: Cc:
Blocked by: Blocking:
Description

If you try to trigger the focus of a field that is hidden (whether it's hidden on it's own, or hidden because the parent element(s) are hidden), IE will throw the following error:

"Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus."

Using .is(':visible') won't work, because the container(s) could be hidden.

However, the fix is pretty simple, by editing the jQuery event core, inside of the trigger method, change this line:

if ( fn && val !== false && !jQuery.nodeName(element, 'a') )
element[ type ]();

To this:

if ( fn && val !== false && !jQuery.nodeName(element, 'a') && !(type == 'focus' && element.offsetHeight == 0) )
element[ type ]();

Of course, I haven't tested this completely thoroughly, but overall, it shouldn't break anything.

Attachments (1)
  • 1486.diff (1.4 KB) - added by brandon September 27, 2007 03:59PM UTC.

    Patch + Tests

Change History (4)

Changed September 27, 2007 03:38PM UTC by brandon comment:1

component: coreevent
milestone: 1.1.41.2.2

Changed September 27, 2007 04:00PM UTC by brandon comment:2

need: ReviewCommit
owner: → brandon

I've attached a patch + tests. I just wrapped the invocation of the native handler in a try catch block.

Changed December 08, 2007 02:55AM UTC by brandon comment:3

resolution: → fixed
status: newclosed

Fixed in Rev [4073]

Changed February 21, 2013 10:23AM UTC by timon.test@gmail.com comment:4

There is still an issue in IE8, when script tries to trigger focus event on disabled element (for example, button).

Is it possible to fix?