Commit 08e57b1d authored by Oleg Gaidarenko's avatar Oleg Gaidarenko Committed by Timmy Willison

Adjust the return value of the tabIndex propHook to match the spec. Fixes #13752.

parent 90eb24e5
...@@ -414,20 +414,14 @@ jQuery.extend({ ...@@ -414,20 +414,14 @@ jQuery.extend({
} }
if ( value !== undefined ) { if ( value !== undefined ) {
if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) { return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
return ret; ret :
( elem[ name ] = value );
} else { } else {
return ( elem[ name ] = value ); return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
} ret :
elem[ name ];
} else {
if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
return ret;
} else {
return elem[ name ];
}
} }
}, },
...@@ -442,7 +436,7 @@ jQuery.extend({ ...@@ -442,7 +436,7 @@ jQuery.extend({
parseInt( attributeNode.value, 10 ) : parseInt( attributeNode.value, 10 ) :
rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ? rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
0 : 0 :
undefined; -1;
} }
} }
} }
......
...@@ -272,6 +272,12 @@ Z</textarea> ...@@ -272,6 +272,12 @@ Z</textarea>
<span>...</span><a id="linkWithNoHrefWithNoTabIndex">Eat a burger</a><span>...</span> <span>...</span><a id="linkWithNoHrefWithNoTabIndex">Eat a burger</a><span>...</span>
<span>...</span><a id="linkWithNoHrefWithTabIndex" tabindex="1">Eat some funyuns</a><span>...</span> <span>...</span><a id="linkWithNoHrefWithTabIndex" tabindex="1">Eat some funyuns</a><span>...</span>
<span>...</span><a id="linkWithNoHrefWithNegativeTabIndex" tabindex="-1">Eat some funyuns</a><span>...</span> <span>...</span><a id="linkWithNoHrefWithNegativeTabIndex" tabindex="-1">Eat some funyuns</a><span>...</span>
<input id="inputWithoutTabIndex"/>
<button id="buttonWithoutTabIndex"></button>
<textarea id="textareaWithoutTabIndex"></textarea>
<menu type="popup">
<menuitem id="menuitemWithoutTabIndex" command="submitbutton" default/>
</menu>
</div> </div>
<div id="liveHandlerOrder"> <div id="liveHandlerOrder">
......
...@@ -687,11 +687,16 @@ test( "prop(String, Object)", function() { ...@@ -687,11 +687,16 @@ test( "prop(String, Object)", function() {
}); });
test( "prop('tabindex')", function() { test( "prop('tabindex')", function() {
expect( 8 ); expect( 11 );
// inputs without tabIndex attribute
equal( jQuery("#inputWithoutTabIndex").prop("tabindex"), 0, "input without tabindex" );
equal( jQuery("#buttonWithoutTabIndex").prop("tabindex"), 0, "button without tabindex" );
equal( jQuery("#textareaWithoutTabIndex").prop("tabindex"), 0, "textarea without tabindex" );
// elements not natively tabbable // elements not natively tabbable
equal( jQuery("#listWithTabIndex").prop("tabindex"), 5, "not natively tabbable, with tabindex set to 0" ); equal( jQuery("#listWithTabIndex").prop("tabindex"), 5, "not natively tabbable, with tabindex set to 0" );
equal( jQuery("#divWithNoTabIndex").prop("tabindex"), undefined, "not natively tabbable, no tabindex set" ); equal( jQuery("#divWithNoTabIndex").prop("tabindex"), -1, "not natively tabbable, no tabindex set" );
// anchor with href // anchor with href
equal( jQuery("#linkWithNoTabIndex").prop("tabindex"), 0, "anchor with href, no tabindex set" ); equal( jQuery("#linkWithNoTabIndex").prop("tabindex"), 0, "anchor with href, no tabindex set" );
...@@ -699,7 +704,7 @@ test( "prop('tabindex')", function() { ...@@ -699,7 +704,7 @@ test( "prop('tabindex')", function() {
equal( jQuery("#linkWithNegativeTabIndex").prop("tabindex"), -1, "anchor with href, tabindex set to -1" ); equal( jQuery("#linkWithNegativeTabIndex").prop("tabindex"), -1, "anchor with href, tabindex set to -1" );
// anchor without href // anchor without href
equal( jQuery("#linkWithNoHrefWithNoTabIndex").prop("tabindex"), undefined, "anchor without href, no tabindex set" ); equal( jQuery("#linkWithNoHrefWithNoTabIndex").prop("tabindex"), -1, "anchor without href, no tabindex set" );
equal( jQuery("#linkWithNoHrefWithTabIndex").prop("tabindex"), 1, "anchor without href, tabindex set to 2" ); equal( jQuery("#linkWithNoHrefWithTabIndex").prop("tabindex"), 1, "anchor without href, tabindex set to 2" );
equal( jQuery("#linkWithNoHrefWithNegativeTabIndex").prop("tabindex"), -1, "anchor without href, no tabindex set" ); equal( jQuery("#linkWithNoHrefWithNegativeTabIndex").prop("tabindex"), -1, "anchor without href, no tabindex set" );
}); });
...@@ -709,7 +714,7 @@ test( "prop('tabindex', value)", 10, function() { ...@@ -709,7 +714,7 @@ test( "prop('tabindex', value)", 10, function() {
var clone, var clone,
element = jQuery("#divWithNoTabIndex"); element = jQuery("#divWithNoTabIndex");
equal( element.prop("tabindex"), undefined, "start with no tabindex" ); equal( element.prop("tabindex"), -1, "start with no tabindex" );
// set a positive string // set a positive string
element.prop( "tabindex", "1" ); element.prop( "tabindex", "1" );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment