Skip to content

Commit

Permalink
fix(runtime-dom): styleprops with initial falsy values should not be …
Browse files Browse the repository at this point in the history
…added as styles.

fix: #5322
  • Loading branch information
LinusBorg committed Jan 31, 2022
1 parent a51f935 commit 2133d1c
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,
'--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('')
})

Expand Down
1 change: 1 addition & 0 deletions packages/runtime-dom/src/modules/style.ts
Expand Up @@ -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 {
Expand Down

0 comments on commit 2133d1c

Please sign in to comment.