Skip to content

Commit

Permalink
fix(runtime-dom/style): fix patchStyle on falsy next value (#1504)
Browse files Browse the repository at this point in the history
fix #1506
  • Loading branch information
jiangying000 authored Jul 6, 2020
1 parent 36b6b4f commit 77538ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/runtime-dom/__tests__/patchStyle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ describe(`runtime-dom: style patching`, () => {
expect(el.style.getPropertyValue('margin-right')).toBe('10px')
})

it('patch with falsy style value', () => {
const el = document.createElement('div')
patchProp(el as any, 'style', { width: '100px' }, { width: 0 })
expect(el.style.width).toBe('0px')
})

// JSDOM doesn't support custom properties on style object so we have to
// mock it here.
function mockElementWithStyle() {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-dom/src/modules/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function patchStyle(el: Element, prev: Style, next: Style) {
}
if (prev && !isString(prev)) {
for (const key in prev) {
if (!next[key]) {
if (next[key] == null) {
setStyle(style, key, '')
}
}
Expand Down

0 comments on commit 77538ec

Please sign in to comment.