Skip to content

Commit 9cc5779

Browse files
committed
fix(v-bind): rendering of custom properties using v-bind
1 parent 5898629 commit 9cc5779

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

packages/shared/src/normalizeProp.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
import { isArray, isString, isObject, hyphenate } from './'
22
import { isNoUnitNumericStyleProp } from './domAttrConfig'
33

4+
const hashedCustomProperty = /^[0-9a-f]{8}-/i;
5+
const customPropertyPrefix = '--';
6+
7+
function normalizeCustomProperty(value: Record<string, string> | string): Record<string, string> | string {
8+
if (isObject(value)) {
9+
const objectKeys = Object.keys(value);
10+
const res: Record<string, string> = {};
11+
12+
for (let i = 0; i < objectKeys.length; i++) {
13+
const item = objectKeys[i];
14+
15+
if (item.match(hashedCustomProperty)) {
16+
res[`${customPropertyPrefix}${item}`] = value[item];
17+
continue;
18+
}
19+
20+
res[item] = value[item];
21+
}
22+
23+
return res;
24+
}
25+
26+
if (value.match(hashedCustomProperty)) {
27+
return `${customPropertyPrefix}${value}`;
28+
}
29+
30+
return value;
31+
}
32+
433
export type NormalizedStyle = Record<string, string | number>
534

635
export function normalizeStyle(
@@ -21,9 +50,9 @@ export function normalizeStyle(
2150
}
2251
return res
2352
} else if (isString(value)) {
24-
return value
53+
return normalizeCustomProperty(value);
2554
} else if (isObject(value)) {
26-
return value
55+
return normalizeCustomProperty(value);
2756
}
2857
}
2958

0 commit comments

Comments
 (0)