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 patching preserve v-show display property properly #4769

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 11 additions & 6 deletions packages/runtime-dom/src/modules/style.ts
Expand Up @@ -6,11 +6,22 @@ type Style = string | Record<string, string | string[]> | null
export function patchStyle(el: Element, prev: Style, next: Style) {
const style = (el as HTMLElement).style
const currentDisplay = style.display
// indicates that the `display` of the element is controlled by `v-show`,
// so we always keep the current `display` value regardless of the `style` value,
// thus handing over control to `v-show`.
const resetDisplay = () => {
if ('_vod' in el) {
style.display = currentDisplay
}
}

if (!next) {
el.removeAttribute('style')
resetDisplay()
} else if (isString(next)) {
if (prev !== next) {
style.cssText = next
resetDisplay()
}
} else {
for (const key in next) {
Expand All @@ -24,12 +35,6 @@ export function patchStyle(el: Element, prev: Style, next: Style) {
}
}
}
// indicates that the `display` of the element is controlled by `v-show`,
// so we always keep the current `display` value regardless of the `style` value,
// thus handing over control to `v-show`.
if ('_vod' in el) {
style.display = currentDisplay
}
}

const importantRE = /\s*!important$/
Expand Down