Skip to content

Commit 79bcb29

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 7855a1a commit 79bcb29

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/css/hiddenVisibleSelectors.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ define([
44
], function( jQuery ) {
55

66
jQuery.expr.filters.hidden = function( elem ) {
7-
// Use OR instead of AND as the element is not visible if either is true
8-
// See tickets #10406 and #13132
9-
return !elem.offsetWidth || !elem.offsetHeight;
7+
return !jQuery.expr.filters.visible( elem );
108
};
119
jQuery.expr.filters.visible = function( elem ) {
12-
return !jQuery.expr.filters.hidden( elem );
10+
return !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length );
1311
};
1412

1513
});

test/unit/css.js

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

926926
test( ":visible/:hidden selectors", function() {
927-
expect( 16 );
927+
expect( 18 );
928928

929-
var $newDiv, $br, $table;
929+
var $div, $br, $table, $a;
930930

931931
ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible" );
932932
jQuery("#nothiddendiv").css({ display: "none" });
@@ -942,11 +942,14 @@ test( ":visible/:hidden selectors", function() {
942942
jQuery("#nothiddendiv").css("display", "block");
943943
ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
944944

945-
ok( !jQuery("#siblingspan").is(":visible"), "Span with no content not visible (#13132)" );
946-
$newDiv = jQuery("<div><span></span></div>").appendTo("#qunit-fixture");
947-
equal( $newDiv.find(":visible").length, 0, "Span with no content not visible (#13132)" );
948-
$br = jQuery("<br/>").appendTo("#qunit-fixture");
949-
ok( !$br.is(":visible"), "br element not visible (#10406)");
945+
ok( jQuery( "#siblingspan" ).is( ":visible" ), "Span with no content is visible" );
946+
$div = jQuery( "<div><span></span></div>" ).appendTo( "#qunit-fixture" );
947+
equal( $div.find( ":visible" ).length, 1, "Span with no content is visible" );
948+
$div.css( { width: 0, height: 0, overflow: "hidden" } );
949+
ok( $div.is( ":visible" ), "Div with width and height of 0 is still visible (gh-2227)" );
950+
951+
$br = jQuery( "<br/>" ).appendTo( "#qunit-fixture" );
952+
ok( $br.is( ":visible" ), "br element is visible" );
950953

951954
$table = jQuery("#table");
952955
$table.html("<tr><td style='display:none'>cell</td><td>cell</td></tr>");
@@ -957,6 +960,9 @@ test( ":visible/:hidden selectors", function() {
957960
t( "Is Visible", "#qunit-fixture div:visible:lt(2)", ["foo", "nothiddendiv"] );
958961
t( "Is Not Hidden", "#qunit-fixture:hidden", [] );
959962
t( "Is Hidden", "#form input:hidden", ["hidden1","hidden2"] );
963+
964+
$a = jQuery( "<a href='#'><h1>Header</h1></a>" ).appendTo( "#qunit-fixture" );
965+
ok( $a.is( ":visible" ), "Anchor tag with flow content is visible (gh-2227)" );
960966
});
961967

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

0 commit comments

Comments
 (0)