Skip to content

Commit 85af139

Browse files
authoredApr 13, 2022
fix(runtime-dom): properly handle style properties with undefined values (#5348)
fix #5322
1 parent f4d2c9f commit 85af139

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed
 

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

+12-1
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+
borderRadius: null
43+
})
44+
expect(el.style.cssText.replace(/\s/g, '')).toBe('')
45+
46+
patchProp(
47+
el,
48+
'style',
49+
{ color: 'red' },
50+
{ color: null, borderRadius: undefined }
51+
)
4152
expect(el.style.cssText.replace(/\s/g, '')).toBe('')
4253
})
4354

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

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function setStyle(
4545
if (isArray(val)) {
4646
val.forEach(v => setStyle(style, name, v))
4747
} else {
48+
if (val == null) val = ''
4849
if (name.startsWith('--')) {
4950
// custom property definition
5051
style.setProperty(name, val)

0 commit comments

Comments
 (0)
Please sign in to comment.