Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-dom): style update error when component use shorthand properties #7425

Merged
merged 2 commits into from Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/runtime-dom/__tests__/patchStyle.spec.ts
Expand Up @@ -106,6 +106,18 @@ describe(`runtime-dom: style patching`, () => {
expect(el.style.getPropertyValue('--custom')).toBe('100\\;')
})

it('shorthand properties', () => {
const el = document.createElement('div')
patchProp(
el as any,
'style',
{ borderBottom: '1px solid red' },
{ border: '1px solid green' }
)
expect(el.style.border).toBe('1px solid green')
expect(el.style.borderBottom).toBe('1px solid green')
})

// JSDOM doesn't support custom properties on style object so we have to
// mock it here.
function mockElementWithStyle() {
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime-dom/src/modules/style.ts
Expand Up @@ -7,16 +7,16 @@ export function patchStyle(el: Element, prev: Style, next: Style) {
const style = (el as HTMLElement).style
const isCssString = isString(next)
if (next && !isCssString) {
for (const key in next) {
setStyle(style, key, next[key])
}
if (prev && !isString(prev)) {
for (const key in prev) {
if (next[key] == null) {
setStyle(style, key, '')
}
}
}
for (const key in next) {
setStyle(style, key, next[key])
}
} else {
const currentDisplay = style.display
if (isCssString) {
Expand Down