diff --git a/packages/runtime-dom/__tests__/patchStyle.spec.ts b/packages/runtime-dom/__tests__/patchStyle.spec.ts index 92b30aa5815..4e7d4e42b48 100644 --- a/packages/runtime-dom/__tests__/patchStyle.spec.ts +++ b/packages/runtime-dom/__tests__/patchStyle.spec.ts @@ -37,7 +37,18 @@ describe(`runtime-dom: style patching`, () => { it('remove if falsy value', () => { const el = document.createElement('div') - patchProp(el, 'style', { color: 'red' }, { color: undefined }) + patchProp(el, 'style', null, { + color: undefined, + '--color': false, + borderRadius: null + }) + expect(el.style.cssText.replace(/\s/g, '')).toBe('') + patchProp( + el, + 'style', + { color: 'red' }, + { color: undefined, '--color': false, borderRadius: false } + ) expect(el.style.cssText.replace(/\s/g, '')).toBe('') }) diff --git a/packages/runtime-dom/src/modules/style.ts b/packages/runtime-dom/src/modules/style.ts index a9cc67ba5e2..1816623bfeb 100644 --- a/packages/runtime-dom/src/modules/style.ts +++ b/packages/runtime-dom/src/modules/style.ts @@ -42,6 +42,7 @@ function setStyle( name: string, val: string | string[] ) { + val = val == null || (val as any) === false ? '' : val if (isArray(val)) { val.forEach(v => setStyle(style, name, v)) } else {