]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-dom/style): fix patchStyle on falsy next value (#1504)
authordjy0 <krivergo3@gmail.com>
Mon, 6 Jul 2020 20:45:15 +0000 (04:45 +0800)
committerGitHub <noreply@github.com>
Mon, 6 Jul 2020 20:45:15 +0000 (16:45 -0400)
fix #1506

packages/runtime-dom/__tests__/patchStyle.spec.ts
packages/runtime-dom/src/modules/style.ts

index 8b701da5781c4ce14ff7325e1483d075dfa07ea3..0755b5154c0cfdc711f2885c01efa05fe9d31c96 100644 (file)
@@ -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() {
index e67e8000e3677ed93a4ea7815955bf0cc17f4af7..518f61d865ee3186f2a5cf9ec4c3da997be67f46 100644 (file)
@@ -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, '')
         }
       }