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 authored and yyx990803 committed Apr 13, 2022
1 parent f4d2c9f commit 4f2deb3
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 4f2deb3

Please sign in to comment.