Skip to content

Commit b6a958e

Browse files
committed
CSS: add limit to trim whitespace only for custom prop
1 parent 04d7e47 commit b6a958e

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/css.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import nodeName from "./core/nodeName.js";
44
import rcssNum from "./var/rcssNum.js";
55
import isIE from "./var/isIE.js";
66
import rnumnonpx from "./css/var/rnumnonpx.js";
7+
import rcustomProp from "./css/var/rcustomProp.js";
78
import cssExpand from "./css/var/cssExpand.js";
89
import isAutoPx from "./css/isAutoPx.js";
910
import cssCamelCase from "./css/cssCamelCase.js";
@@ -24,7 +25,6 @@ var
2425
// except "table", "table-cell", or "table-caption"
2526
// See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
2627
rdisplayswap = /^(none|table(?!-c[ea]).+)/,
27-
rcustomProp = /^--/,
2828
cssShow = { position: "absolute", visibility: "hidden", display: "block" },
2929
cssNormalTransform = {
3030
letterSpacing: "0",

src/css/curCSS.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import jQuery from "../core.js";
22
import isAttached from "../core/isAttached.js";
33
import getStyles from "./var/getStyles.js";
4+
import rcustomProp from "./var/rcustomProp.js";
45

56
function curCSS( elem, name, computed ) {
6-
var ret;
7+
var ret,
8+
isCustomProp = rcustomProp.test( name );
79

810
computed = computed || getStyles( elem );
911

1012
// getPropertyValue is needed for `.css('--customProperty')` (gh-3144)
1113
if ( computed ) {
12-
ret = computed.getPropertyValue( name );
14+
ret = computed.getPropertyValue( name ) || computed[ name ];
1315

14-
// trim whitespace (issue #4926)
15-
ret = ( ret && ret.trim() ) || computed[ name ];
16+
// trim whitespace for custom property (issue #4926)
17+
if ( isCustomProp ) {
18+
ret = ret.trim();
19+
}
1620

1721
if ( ret === "" && !isAttached( elem ) ) {
1822
ret = jQuery.style( elem, name );

src/css/var/rcustomProp.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default ( /^--/ );

0 commit comments

Comments
 (0)