Skip to content

Commit

Permalink
fix(runtime-dom): properly handle style properties with undefined val…
Browse files Browse the repository at this point in the history
…ues (#5348)

fix #5322
  • Loading branch information
LinusBorg committed Apr 13, 2022
1 parent f4d2c9f commit 85af139
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/runtime-dom/__tests__/patchStyle.spec.ts
Expand Up @@ -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,
borderRadius: null
})
expect(el.style.cssText.replace(/\s/g, '')).toBe('')

patchProp(
el,
'style',
{ color: 'red' },
{ color: null, borderRadius: undefined }
)
expect(el.style.cssText.replace(/\s/g, '')).toBe('')
})

Expand Down
1 change: 1 addition & 0 deletions packages/runtime-dom/src/modules/style.ts
Expand Up @@ -45,6 +45,7 @@ function setStyle(
if (isArray(val)) {
val.forEach(v => setStyle(style, name, v))
} else {
if (val == null) val = ''
if (name.startsWith('--')) {
// custom property definition
style.setProperty(name, val)
Expand Down

0 comments on commit 85af139

Please sign in to comment.