Skip to content

Commit dd816db

Browse files
committed
CSS: fix :visible/:hidden selectors for inline element w/ content
- Reverts behavior from 10399dd, which we never released. BR and inline elements are considered visible. - The possibility of dropping .offsetWidth and .offsetHeight was debunked by this perf: http://jsperf.com/visible-hidden-and-getclientrects Fixes gh-2227 Close gh-2281
1 parent fe2a584 commit dd816db

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/css/hiddenVisibleSelectors.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ define([
66
], function( jQuery, support ) {
77

88
jQuery.expr.filters.hidden = function( elem ) {
9-
// Use OR instead of AND as the element is not visible if either is true
10-
// See tickets #10406 and #13132
11-
return !elem.offsetWidth || !elem.offsetHeight ||
12-
(!support.reliableHiddenOffsets() &&
13-
((elem.style && elem.style.display) || jQuery.css( elem, "display" )) === "none");
9+
return !jQuery.expr.filters.visible( elem );
1410
};
1511

1612
jQuery.expr.filters.visible = function( elem ) {
17-
return !jQuery.expr.filters.hidden( elem );
13+
return !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length ) &&
14+
( support.reliableHiddenOffsets() ||
15+
( ( elem.style && elem.style.display ) || jQuery.css( elem, "display" ) ) !== "none" );
1816
};
1917

2018
});

test/unit/css.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -982,9 +982,9 @@ test( "css opacity consistency across browsers (#12685)", function() {
982982
});
983983

984984
test( ":visible/:hidden selectors", function() {
985-
expect( 16 );
985+
expect( 18 );
986986

987-
var $newDiv, $br, $table;
987+
var $div, $br, $table, $a;
988988

989989
ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible" );
990990
jQuery("#nothiddendiv").css({ display: "none" });
@@ -1000,11 +1000,14 @@ test( ":visible/:hidden selectors", function() {
10001000
jQuery("#nothiddendiv").css("display", "block");
10011001
ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
10021002

1003-
ok( !jQuery("#siblingspan").is(":visible"), "Span with no content not visible (#13132)" );
1004-
$newDiv = jQuery("<div><span></span></div>").appendTo("#qunit-fixture");
1005-
equal( $newDiv.find(":visible").length, 0, "Span with no content not visible (#13132)" );
1006-
$br = jQuery("<br/>").appendTo("#qunit-fixture");
1007-
ok( !$br.is(":visible"), "br element not visible (#10406)");
1003+
ok( jQuery( "#siblingspan" ).is( ":visible" ), "Span with no content is visible" );
1004+
$div = jQuery( "<div><span></span></div>" ).appendTo( "#qunit-fixture" );
1005+
equal( $div.find( ":visible" ).length, 1, "Span with no content is visible" );
1006+
$div.css( { width: 0, height: 0, overflow: "hidden" } );
1007+
ok( $div.is( ":visible" ), "Div with width and height of 0 is still visible (gh-2227)" );
1008+
1009+
$br = jQuery( "<br/>" ).appendTo( "#qunit-fixture" );
1010+
ok( $br.is( ":visible" ), "br element is visible" );
10081011

10091012
$table = jQuery("#table");
10101013
$table.html("<tr><td style='display:none'>cell</td><td>cell</td></tr>");
@@ -1015,6 +1018,9 @@ test( ":visible/:hidden selectors", function() {
10151018
t( "Is Visible", "#qunit-fixture div:visible:lt(2)", ["foo", "nothiddendiv"] );
10161019
t( "Is Not Hidden", "#qunit-fixture:hidden", [] );
10171020
t( "Is Hidden", "#form input:hidden", ["hidden1","hidden2"] );
1021+
1022+
$a = jQuery( "<a href='#'><h1>Header</h1></a>" ).appendTo( "#qunit-fixture" );
1023+
ok( $a.is( ":visible" ), "Anchor tag with flow content is visible (gh-2227)" );
10181024
});
10191025

10201026
test( "Keep the last style if the new one isn't recognized by the browser (#14836)", function() {

0 commit comments

Comments
 (0)