Skip to content

Commit d302596

Browse files
committed
Focusable: Fix handling of visibility: inherit
Ref #14596 Ref gh-1583 Closes gh-1605
1 parent 0bfbd21 commit d302596

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

tests/unit/core/core.html

+11-1
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,20 @@
8181
<input id="visibilityHiddenAncestor-input">
8282
<span tabindex="1" id="visibilityHiddenAncestor-span">.</span>
8383

84-
<span id="nestedVisibilityOverrideAncestor" style="visibility: visible">
84+
<span id="nestedVisibilityOverrideAncestor" style="visibility: visible;">
8585
<input id="nestedVisibilityOverrideAncestor-input">
8686
<span tabindex="1" id="nestedVisibilityOverrideAncestor-span">.</span>
8787
</span>
88+
89+
<span tabIndex="1" id="nestedVisibilityInheritWithHiddenAncestor"
90+
style="visibility: inherit;">.</span>
91+
<input id="nestedVisibilityInheritWithHiddenAncestor-input" style="visibility: inherit;">
92+
</div>
93+
94+
<div id="visibilityVisibleAncestor" style="visibility: visible;">
95+
<span tabIndex="1" id="nestedVisibilityInheritWithVisibleAncestor"
96+
style="visibility: inherit;">.</span>
97+
<input id="nestedVisibilityInheritWithVisibleAncestor-input" style="visibility: inherit;">
8898
</div>
8999

90100
<span tabindex="1" id="displayNone-span" style="display: none;">.</span>

tests/unit/core/selector.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ test( "data", function() {
8888
} );
8989

9090
test( "focusable - visible, enabled elements", function() {
91-
expect( 18 );
91+
expect( 20 );
9292

9393
isNotFocusable( "#formNoTabindex", "form" );
9494
isFocusable( "#formTabindex", "form with tabindex" );
@@ -108,6 +108,10 @@ test( "focusable - visible, enabled elements", function() {
108108
isNotFocusable( "#visibleAncestor-div", "div" );
109109
isFocusable( "#visibleAncestor-spanWithTabindex", "span with tabindex" );
110110
isFocusable( "#visibleAncestor-divWithNegativeTabindex", "div with tabindex" );
111+
isFocusable( "#nestedVisibilityInheritWithVisibleAncestor",
112+
"span, visibility: inherit inside visibility: visible parent" );
113+
isFocusable( "#nestedVisibilityInheritWithVisibleAncestor-input",
114+
"input, visibility: inherit inside visibility: visible parent" );
111115
} );
112116

113117
test( "focusable - disabled elements", function() {
@@ -125,7 +129,7 @@ test( "focusable - disabled elements", function() {
125129
} );
126130

127131
test( "focusable - hidden styles", function() {
128-
expect( 10 );
132+
expect( 12 );
129133

130134
isNotFocusable( "#displayNoneAncestor-input", "input, display: none parent" );
131135
isNotFocusable( "#displayNoneAncestor-span", "span with tabindex, display: none parent" );
@@ -136,6 +140,9 @@ test( "focusable - hidden styles", function() {
136140
isFocusable( "#nestedVisibilityOverrideAncestor-input", "input, visibility: visible parent but visibility: hidden grandparent" );
137141
isFocusable( "#nestedVisibilityOverrideAncestor-span", "span with tabindex, visibility: visible parent but visibility: hidden grandparent " );
138142

143+
isNotFocusable( "#nestedVisibilityInheritWithHiddenAncestor", "span, visibility: inherit inside visibility: hidden parent" );
144+
isNotFocusable( "#nestedVisibilityInheritWithHiddenAncestor-input", "input, visibility: inherit inside visibility: hidden parent" );
145+
139146
isNotFocusable( "#displayNone-input", "input, display: none" );
140147
isNotFocusable( "#visibilityHidden-input", "input, visibility: hidden" );
141148

ui/focusable.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,20 @@ $.ui.focusable = function( element, hasTabindex ) {
4242
"a" === nodeName ?
4343
element.href || hasTabindex :
4444
hasTabindex ) &&
45-
$( element ).is( ":visible" ) && $( element ).css( "visibility" ) === "visible";
45+
$( element ).is( ":visible" ) && visible( $( element ) );
4646
};
4747

48+
// Support: IE 8 only
49+
// IE 8 doesn't resolve inherit to visible/hidden for computed values
50+
function visible( element ) {
51+
var visibility = element.css( "visibility" );
52+
while ( visibility === "inherit" ) {
53+
element = element.parent();
54+
visibility = element.css( "visibility" );
55+
}
56+
return visibility !== "hidden";
57+
}
58+
4859
$.extend( $.expr[ ":" ], {
4960
focusable: function( element ) {
5061
return $.ui.focusable( element, $.attr( element, "tabindex" ) != null );

0 commit comments

Comments
 (0)