Skip to content

Commit c752a50

Browse files
Queeniebeemgol
authored andcommitted
Attributes: fix tabIndex on <img> in IE11
Fixes gh-2647 Closes gh-2664
1 parent 3689963 commit c752a50

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/attributes/prop.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ define( [
55
"../selector"
66
], function( jQuery, access, support ) {
77

8-
var rfocusable = /^(?:input|select|textarea|button)$/i;
8+
var rfocusable = /^(?:input|select|textarea|button)$/i,
9+
rclickable = /^(?:a|area)$/i;
910

1011
jQuery.fn.extend( {
1112
prop: function( name, value ) {
@@ -55,10 +56,19 @@ jQuery.extend( {
5556
propHooks: {
5657
tabIndex: {
5758
get: function( elem ) {
58-
return elem.hasAttribute( "tabindex" ) ||
59-
rfocusable.test( elem.nodeName ) || elem.href ?
60-
elem.tabIndex :
61-
-1;
59+
60+
// elem.tabIndex doesn't always return the
61+
// correct value when it hasn't been explicitly set
62+
// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
63+
// Use proper attribute retrieval(#12072)
64+
var tabindex = jQuery.find.attr( elem, "tabindex" );
65+
66+
return tabindex ?
67+
parseInt( tabindex, 10 ) :
68+
rfocusable.test( elem.nodeName ) ||
69+
rclickable.test( elem.nodeName ) && elem.href ?
70+
0 :
71+
-1;
6272
}
6373
}
6474
},

test/unit/attributes.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,13 @@ QUnit.test( "prop('tabindex')", function( assert ) {
735735
assert.equal( jQuery( "#linkWithNoHrefWithNegativeTabIndex" ).prop( "tabindex" ), -1, "anchor without href, no tabindex set" );
736736
} );
737737

738+
QUnit.test( "image.prop( 'tabIndex' )", function( assert ) {
739+
assert.expect( 1 );
740+
var image = jQuery("<img src='data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' />")
741+
.appendTo("#qunit-fixture");
742+
assert.equal( image.prop("tabIndex" ), -1, "tabIndex on image" );
743+
} );
744+
738745
QUnit.test( "prop('tabindex', value)", function( assert ) {
739746
assert.expect( 10 );
740747

0 commit comments

Comments
 (0)