From: djy0 Date: Mon, 6 Jul 2020 20:45:15 +0000 (+0800) Subject: fix(runtime-dom/style): fix patchStyle on falsy next value (#1504) X-Git-Tag: v3.0.0-beta.19~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77538ec6d90fee66d229d6d3a4f977c6b548a9bd;p=thirdparty%2Fvuejs%2Fcore.git fix(runtime-dom/style): fix patchStyle on falsy next value (#1504) fix #1506 --- diff --git a/packages/runtime-dom/__tests__/patchStyle.spec.ts b/packages/runtime-dom/__tests__/patchStyle.spec.ts index 8b701da578..0755b5154c 100644 --- a/packages/runtime-dom/__tests__/patchStyle.spec.ts +++ b/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() { diff --git a/packages/runtime-dom/src/modules/style.ts b/packages/runtime-dom/src/modules/style.ts index e67e8000e3..518f61d865 100644 --- a/packages/runtime-dom/src/modules/style.ts +++ b/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, '') } }