Преглед на файлове

fix(runtime-dom/style): fix patchStyle on falsy next value (#1504)

fix #1506
djy0 преди 5 години
родител
ревизия
77538ec6d9
променени са 2 файла, в които са добавени 7 реда и са изтрити 1 реда
  1. 6 0
      packages/runtime-dom/__tests__/patchStyle.spec.ts
  2. 1 1
      packages/runtime-dom/src/modules/style.ts

+ 6 - 0
packages/runtime-dom/__tests__/patchStyle.spec.ts

@@ -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() {

+ 1 - 1
packages/runtime-dom/src/modules/style.ts

@@ -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, '')
         }
       }