Skip to content

Commit b7cfa6f

Browse files
authored
fix(runtime-dom): style update error when component use shorthand properties (#7425)
* fix(runtime-dom): style update error when component use shorthand properties * test(runtime-dom): style update with shorthand properties
1 parent 686c829 commit b7cfa6f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/runtime-dom/__tests__/patchStyle.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ describe(`runtime-dom: style patching`, () => {
106106
expect(el.style.getPropertyValue('--custom')).toBe('100\\;')
107107
})
108108

109+
it('shorthand properties', () => {
110+
const el = document.createElement('div')
111+
patchProp(
112+
el as any,
113+
'style',
114+
{ borderBottom: '1px solid red' },
115+
{ border: '1px solid green' }
116+
)
117+
expect(el.style.border).toBe('1px solid green')
118+
expect(el.style.borderBottom).toBe('1px solid green')
119+
})
120+
109121
// JSDOM doesn't support custom properties on style object so we have to
110122
// mock it here.
111123
function mockElementWithStyle() {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ export function patchStyle(el: Element, prev: Style, next: Style) {
77
const style = (el as HTMLElement).style
88
const isCssString = isString(next)
99
if (next && !isCssString) {
10-
for (const key in next) {
11-
setStyle(style, key, next[key])
12-
}
1310
if (prev && !isString(prev)) {
1411
for (const key in prev) {
1512
if (next[key] == null) {
1613
setStyle(style, key, '')
1714
}
1815
}
1916
}
17+
for (const key in next) {
18+
setStyle(style, key, next[key])
19+
}
2020
} else {
2121
const currentDisplay = style.display
2222
if (isCssString) {

0 commit comments

Comments
 (0)