From f41fec26ba5b18e404b5a9cf5e823814c98e0c4c Mon Sep 17 00:00:00 2001 From: Carl Chen <71313168+cc-hearts@users.noreply.github.com> Date: Sun, 9 Jun 2024 09:56:45 +0800 Subject: [PATCH] fix[vc-util]: styleObjectToString filter invalid value (#7642) --- components/vc-util/Dom/css.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/components/vc-util/Dom/css.ts b/components/vc-util/Dom/css.ts index 512a2609f..7cb597dfe 100644 --- a/components/vc-util/Dom/css.ts +++ b/components/vc-util/Dom/css.ts @@ -121,7 +121,13 @@ export function styleToString(style: CSSStyleDeclaration) { } export function styleObjectToString(style: Record) { - return Object.keys(style) - .map(name => `${name}: ${style[name]};`) - .join(''); + return Object.keys(style).reduce((acc, name) => { + const styleValue = style[name]; + if (typeof styleValue === 'undefined' || styleValue === null) { + return acc; + } + + acc += `${name}: ${style[name]};`; + return acc; + }, ''); }