mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Core: Remove ancestor visibility requirement from :focusable
selector
* Check computed visibility in addition to :visible * Add tests for nested visibility override Fixes #14596 Closes gh-1583
This commit is contained in:
parent
6308a261fd
commit
0db243a736
@ -80,6 +80,11 @@
|
|||||||
<div id="visibilityHiddenAncestor" style="visibility: hidden;">
|
<div id="visibilityHiddenAncestor" style="visibility: hidden;">
|
||||||
<input id="visibilityHiddenAncestor-input">
|
<input id="visibilityHiddenAncestor-input">
|
||||||
<span tabindex="1" id="visibilityHiddenAncestor-span">.</span>
|
<span tabindex="1" id="visibilityHiddenAncestor-span">.</span>
|
||||||
|
|
||||||
|
<span id="nestedVisibilityOverrideAncestor" style="visibility: visible">
|
||||||
|
<input id="nestedVisibilityOverrideAncestor-input">
|
||||||
|
<span tabindex="1" id="nestedVisibilityOverrideAncestor-span">.</span>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span tabindex="1" id="displayNone-span" style="display: none;">.</span>
|
<span tabindex="1" id="displayNone-span" style="display: none;">.</span>
|
||||||
|
@ -125,7 +125,7 @@ test( "focusable - disabled elements", function() {
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
test( "focusable - hidden styles", function() {
|
test( "focusable - hidden styles", function() {
|
||||||
expect( 8 );
|
expect( 10 );
|
||||||
|
|
||||||
isNotFocusable( "#displayNoneAncestor-input", "input, display: none parent" );
|
isNotFocusable( "#displayNoneAncestor-input", "input, display: none parent" );
|
||||||
isNotFocusable( "#displayNoneAncestor-span", "span with tabindex, display: none parent" );
|
isNotFocusable( "#displayNoneAncestor-span", "span with tabindex, display: none parent" );
|
||||||
@ -133,6 +133,9 @@ test( "focusable - hidden styles", function() {
|
|||||||
isNotFocusable( "#visibilityHiddenAncestor-input", "input, visibility: hidden parent" );
|
isNotFocusable( "#visibilityHiddenAncestor-input", "input, visibility: hidden parent" );
|
||||||
isNotFocusable( "#visibilityHiddenAncestor-span", "span with tabindex, visibility: hidden parent" );
|
isNotFocusable( "#visibilityHiddenAncestor-span", "span with tabindex, visibility: hidden parent" );
|
||||||
|
|
||||||
|
isFocusable( "#nestedVisibilityOverrideAncestor-input", "input, visibility: visible parent but visibility: hidden grandparent" );
|
||||||
|
isFocusable( "#nestedVisibilityOverrideAncestor-span", "span with tabindex, visibility: visible parent but visibility: hidden grandparent " );
|
||||||
|
|
||||||
isNotFocusable( "#displayNone-input", "input, display: none" );
|
isNotFocusable( "#displayNone-input", "input, display: none" );
|
||||||
isNotFocusable( "#visibilityHidden-input", "input, visibility: hidden" );
|
isNotFocusable( "#visibilityHidden-input", "input, visibility: hidden" );
|
||||||
|
|
||||||
@ -210,7 +213,7 @@ test( "tabbable - disabled elements", function() {
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
test( "tabbable - hidden styles", function() {
|
test( "tabbable - hidden styles", function() {
|
||||||
expect( 8 );
|
expect( 10 );
|
||||||
|
|
||||||
isNotTabbable( "#displayNoneAncestor-input", "input, display: none parent" );
|
isNotTabbable( "#displayNoneAncestor-input", "input, display: none parent" );
|
||||||
isNotTabbable( "#displayNoneAncestor-span", "span with tabindex, display: none parent" );
|
isNotTabbable( "#displayNoneAncestor-span", "span with tabindex, display: none parent" );
|
||||||
@ -218,6 +221,9 @@ test( "tabbable - hidden styles", function() {
|
|||||||
isNotTabbable( "#visibilityHiddenAncestor-input", "input, visibility: hidden parent" );
|
isNotTabbable( "#visibilityHiddenAncestor-input", "input, visibility: hidden parent" );
|
||||||
isNotTabbable( "#visibilityHiddenAncestor-span", "span with tabindex, visibility: hidden parent" );
|
isNotTabbable( "#visibilityHiddenAncestor-span", "span with tabindex, visibility: hidden parent" );
|
||||||
|
|
||||||
|
isTabbable( "#nestedVisibilityOverrideAncestor-input", "input, visibility: visible parent but visibility: hidden grandparent" );
|
||||||
|
isTabbable( "#nestedVisibilityOverrideAncestor-span", "span with tabindex, visibility: visible parent but visibility: hidden grandparent " );
|
||||||
|
|
||||||
isNotTabbable( "#displayNone-input", "input, display: none" );
|
isNotTabbable( "#displayNone-input", "input, display: none" );
|
||||||
isNotTabbable( "#visibilityHidden-input", "input, visibility: hidden" );
|
isNotTabbable( "#visibilityHidden-input", "input, visibility: hidden" );
|
||||||
|
|
||||||
|
@ -34,26 +34,17 @@ $.ui.focusable = function( element, hasTabindex ) {
|
|||||||
if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
|
if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
img = $( "img[usemap='#" + mapName + "']" )[ 0 ];
|
img = $( "img[usemap='#" + mapName + "']" );
|
||||||
return !!img && visible( img );
|
return img.length > 0 && img.is( ":visible" );
|
||||||
}
|
}
|
||||||
return ( /^(input|select|textarea|button|object)$/.test( nodeName ) ?
|
return ( /^(input|select|textarea|button|object)$/.test( nodeName ) ?
|
||||||
!element.disabled :
|
!element.disabled :
|
||||||
"a" === nodeName ?
|
"a" === nodeName ?
|
||||||
element.href || hasTabindex :
|
element.href || hasTabindex :
|
||||||
hasTabindex ) &&
|
hasTabindex ) &&
|
||||||
|
$( element ).is( ":visible" ) && $( element ).css( "visibility" ) === "visible";
|
||||||
// The element and all of its ancestors must be visible
|
|
||||||
visible( element );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function visible( element ) {
|
|
||||||
return $.expr.filters.visible( element ) &&
|
|
||||||
!$( element ).parents().addBack().filter( function() {
|
|
||||||
return $.css( this, "visibility" ) === "hidden";
|
|
||||||
} ).length;
|
|
||||||
}
|
|
||||||
|
|
||||||
$.extend( $.expr[ ":" ], {
|
$.extend( $.expr[ ":" ], {
|
||||||
focusable: function( element ) {
|
focusable: function( element ) {
|
||||||
return $.ui.focusable( element, $.attr( element, "tabindex" ) != null );
|
return $.ui.focusable( element, $.attr( element, "tabindex" ) != null );
|
||||||
|
Loading…
Reference in New Issue
Block a user