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): fix conflicts between v-show and style display binding #4770

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 4 additions & 2 deletions packages/runtime-dom/src/directives/vShow.ts
@@ -1,8 +1,10 @@
import { ObjectDirective } from '@vue/runtime-core'

interface VShowElement extends HTMLElement {
export interface VShowElement extends HTMLElement {
// _vod = vue original display
_vod: string
// _vds = vue display status
_vds: boolean
}

export const vShow: ObjectDirective<VShowElement> = {
Expand Down Expand Up @@ -41,7 +43,7 @@ export const vShow: ObjectDirective<VShowElement> = {
}

function setDisplay(el: VShowElement, value: unknown): void {
el.style.display = value ? el._vod : 'none'
el.style.display = (el._vds = !!value) ? el._vod : 'none'
}

// SSR vnode transforms, only used when user includes client-oriented render
Expand Down
9 changes: 7 additions & 2 deletions packages/runtime-dom/src/modules/style.ts
@@ -1,5 +1,6 @@
import { isString, hyphenate, capitalize, isArray } from '@vue/shared'
import { camelize } from '@vue/runtime-core'
import { VShowElement } from '../directives/vShow'

type Style = string | Record<string, string | string[]> | null

Expand Down Expand Up @@ -27,8 +28,12 @@ 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
if ('_vod' in el && currentDisplay !== style.display) {
(el as VShowElement)._vod = style.display;
if (!(el as VShowElement)._vds) {
// if vshow was set to hide
style.display = currentDisplay;
}
}
}

Expand Down