mirror of https://github.com/vuejs/core.git
fix(runtime-dom): unify behavior for v-show + style display binding (#10075)
close #10074
This commit is contained in:
parent
dcc68ef7d4
commit
cd419aec3c
|
@ -7,6 +7,7 @@ type Style = string | Record<string, string | string[]> | null
|
||||||
|
|
||||||
export function patchStyle(el: Element, prev: Style, next: Style) {
|
export function patchStyle(el: Element, prev: Style, next: Style) {
|
||||||
const style = (el as HTMLElement).style
|
const style = (el as HTMLElement).style
|
||||||
|
const currentDisplay = style.display
|
||||||
const isCssString = isString(next)
|
const isCssString = isString(next)
|
||||||
if (next && !isCssString) {
|
if (next && !isCssString) {
|
||||||
if (prev && !isString(prev)) {
|
if (prev && !isString(prev)) {
|
||||||
|
@ -20,7 +21,6 @@ export function patchStyle(el: Element, prev: Style, next: Style) {
|
||||||
setStyle(style, key, next[key])
|
setStyle(style, key, next[key])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const currentDisplay = style.display
|
|
||||||
if (isCssString) {
|
if (isCssString) {
|
||||||
if (prev !== next) {
|
if (prev !== next) {
|
||||||
// #9821
|
// #9821
|
||||||
|
@ -33,6 +33,7 @@ export function patchStyle(el: Element, prev: Style, next: Style) {
|
||||||
} else if (prev) {
|
} else if (prev) {
|
||||||
el.removeAttribute('style')
|
el.removeAttribute('style')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// indicates that the `display` of the element is controlled by `v-show`,
|
// indicates that the `display` of the element is controlled by `v-show`,
|
||||||
// so we always keep the current `display` value regardless of the `style`
|
// so we always keep the current `display` value regardless of the `style`
|
||||||
// value, thus handing over control to `v-show`.
|
// value, thus handing over control to `v-show`.
|
||||||
|
@ -40,7 +41,6 @@ export function patchStyle(el: Element, prev: Style, next: Style) {
|
||||||
style.display = currentDisplay
|
style.display = currentDisplay
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const semicolonRE = /[^\\];\s*$/
|
const semicolonRE = /[^\\];\s*$/
|
||||||
const importantRE = /\s*!important$/
|
const importantRE = /\s*!important$/
|
||||||
|
|
Loading…
Reference in New Issue