Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v-bind): rendering of custom properties using v-bind (fix #5443) #5444

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions packages/shared/src/normalizeProp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
import { isArray, isString, isObject, hyphenate } from './'
import { isNoUnitNumericStyleProp } from './domAttrConfig'

const hashedCustomProperty = /^[0-9a-f]{8}/i;
const customPropertyPrefix = '--';

function normalizeCustomProperty(value: Record<string, string> | string): Record<string, string> | string {
if (isObject(value)) {
const objectKeys = Object.keys(value);
const res: Record<string, string> = {};

for (let i = 0; i < objectKeys.length; i++) {
const item = objectKeys[i];

if (item.match(hashedCustomProperty)) {
res[`${customPropertyPrefix}${item}`] = value[item];
continue;
}

res[item] = value[item];
}

return res;
}

if (value.match(hashedCustomProperty)) {
return `${customPropertyPrefix}${value}`;
}

return value;
}

export type NormalizedStyle = Record<string, string | number>

export function normalizeStyle(
Expand All @@ -21,9 +50,9 @@ export function normalizeStyle(
}
return res
} else if (isString(value)) {
return value
return normalizeCustomProperty(value);
} else if (isObject(value)) {
return value
return normalizeCustomProperty(value);
}
}

Expand Down