Skip to content

Commit 2133d1c

Browse files
committed
fix(runtime-dom): styleprops with initial falsy values should not be added as styles.
fix: #5322
1 parent a51f935 commit 2133d1c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/runtime-dom/__tests__/patchStyle.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,18 @@ describe(`runtime-dom: style patching`, () => {
3737

3838
it('remove if falsy value', () => {
3939
const el = document.createElement('div')
40-
patchProp(el, 'style', { color: 'red' }, { color: undefined })
40+
patchProp(el, 'style', null, {
41+
color: undefined,
42+
'--color': false,
43+
borderRadius: null
44+
})
45+
expect(el.style.cssText.replace(/\s/g, '')).toBe('')
46+
patchProp(
47+
el,
48+
'style',
49+
{ color: 'red' },
50+
{ color: undefined, '--color': false, borderRadius: false }
51+
)
4152
expect(el.style.cssText.replace(/\s/g, '')).toBe('')
4253
})
4354

packages/runtime-dom/src/modules/style.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function setStyle(
4242
name: string,
4343
val: string | string[]
4444
) {
45+
val = val == null || (val as any) === false ? '' : val
4546
if (isArray(val)) {
4647
val.forEach(v => setStyle(style, name, v))
4748
} else {

0 commit comments

Comments
 (0)