🌐 AI搜索 & 代理 主页
Skip to content

Commit 75b77b4

Browse files
authored
CSS: Don't auto-append "px" to CSS variables (#4064)
Fixes gh-4063 Closes gh-4064
1 parent 45f0858 commit 75b77b4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/css.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ jQuery.extend( {
246246
}
247247

248248
// If a number was passed in, add the unit (except for certain CSS properties)
249-
if ( type === "number" ) {
249+
// The isCustomProp check can be removed in jQuery 4.0 when we only auto-append
250+
// "px" to a few hardcoded values.
251+
if ( type === "number" && !isCustomProp ) {
250252
value += ret && ret[ 3 ] || ( jQuery.cssNumber[ origName ] ? "" : "px" );
251253
}
252254

test/unit/css.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,21 @@ QUnit.test( "Do not throw on frame elements from css method (#15098)", function(
16591659
assert.equal( $elem.css( "--prop5" ), "'val5'", "Works with single quotes" );
16601660
}
16611661
} );
1662+
1663+
QUnit[ supportsCssVars ? "test" : "skip" ]( "Don't append px to CSS vars", function( assert ) {
1664+
assert.expect( 3 );
1665+
1666+
var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
1667+
1668+
$div
1669+
.css( "--a", 3 )
1670+
.css( "--line-height", 4 )
1671+
.css( "--lineHeight", 5 );
1672+
1673+
assert.equal( $div.css( "--a" ), "3", "--a: 3" );
1674+
assert.equal( $div.css( "--line-height" ), "4", "--line-height: 4" );
1675+
assert.equal( $div.css( "--lineHeight" ), "5", "--lineHeight: 5" );
1676+
} );
16621677
} )();
16631678

16641679
}

0 commit comments

Comments
 (0)