Skip to content

Commit

Permalink
Dimensions: Modify reliableTrDimensions support test to account for FF
Browse files Browse the repository at this point in the history
Firefox incorrectly (or perhaps correctly) includes table borders in computed
dimensions, but they are the only one. Workaround this by testing for it and
falling back to offset properties

Fixes gh-4529
Closes gh-4807
  • Loading branch information
timmywil committed Jan 11, 2021
1 parent bf06dd4 commit bcd40aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
15 changes: 13 additions & 2 deletions src/css/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,23 @@ define( [
// set in CSS while `offset*` properties report correct values.
// Behavior in IE 9 is more subtle than in newer versions & it passes
// some versions of this test; make sure not to make it pass there!
//
// Support: Firefox 70+
// Only Firefox includes border widths
// in computed dimensions. (gh-4529)
reliableTrDimensions: function() {
var table, tr, trChild, trStyle;
if ( reliableTrDimensionsVal == null ) {
table = document.createElement( "table" );
tr = document.createElement( "tr" );
trChild = document.createElement( "div" );

table.style.cssText = "position:absolute;left:-11111px";
table.style.cssText = "position:absolute;left:-11111px;border-collapse:separate";
tr.style.cssText = "border:1px solid";

// Support: Chrome 86+
// Height set through cssText does not get applied.
// Computed height then comes back as 0.
tr.style.height = "1px";
trChild.style.height = "9px";

Expand All @@ -119,7 +128,9 @@ define( [
.appendChild( trChild );

trStyle = window.getComputedStyle( tr );
reliableTrDimensionsVal = parseInt( trStyle.height ) > 3;
reliableTrDimensionsVal = ( parseInt( trStyle.height, 10 ) +
parseInt( trStyle.borderTopWidth, 10 ) +
parseInt( trStyle.borderBottomWidth, 10 ) ) === tr.offsetHeight;

documentElement.removeChild( table );
}
Expand Down
8 changes: 1 addition & 7 deletions test/unit/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,13 +627,7 @@ QUnit.test( "width/height on an inline element with percentage dimensions (gh-36
}
);

// Support: Firefox 70+
// Firefox 70 & newer fail this test but the issue there is more profound - Firefox doesn't
// subtract borders from table row computed widths.
// See https://github.com/jquery/jquery/issues/4529
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1590837
// See https://github.com/w3c/csswg-drafts/issues/4444
QUnit[ /firefox/i.test( navigator.userAgent ) ? "skip" : "test" ](
QUnit.test(
"width/height on a table row with phantom borders (gh-3698)", function( assert ) {
assert.expect( 4 );

Expand Down
2 changes: 1 addition & 1 deletion test/unit/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ testIframe(
"pixelPosition": true,
"radioValue": true,
"reliableMarginLeft": true,
"reliableTrDimensions": true,
"reliableTrDimensions": false,
"scrollboxSize": true
},
firefox_60: {
Expand Down

0 comments on commit bcd40aa

Please sign in to comment.