1
1
import { capitalize , hyphenate , isArray , isString } from '@vue/shared'
2
2
import { camelize , warn } from '@vue/runtime-core'
3
- import { vShowOriginalDisplay } from '../directives/vShow'
3
+ import {
4
+ type VShowElement ,
5
+ vShowHidden ,
6
+ vShowOriginalDisplay ,
7
+ } from '../directives/vShow'
4
8
import { CSS_VAR_TEXT } from '../helpers/useCssVars'
5
9
6
10
type Style = string | Record < string , string | string [ ] > | null
@@ -10,7 +14,6 @@ const displayRE = /(^|;)\s*display\s*:/
10
14
export function patchStyle ( el : Element , prev : Style , next : Style ) {
11
15
const style = ( el as HTMLElement ) . style
12
16
const isCssString = isString ( next )
13
- const currentDisplay = style . display
14
17
let hasControlledDisplay = false
15
18
if ( next && ! isCssString ) {
16
19
if ( prev ) {
@@ -50,12 +53,14 @@ export function patchStyle(el: Element, prev: Style, next: Style) {
50
53
el . removeAttribute ( 'style' )
51
54
}
52
55
}
53
- // indicates that the `display` of the element is controlled by `v-show`,
54
- // so we always keep the current `display` value regardless of the `style`
55
- // value, thus handing over control to `v-show`.
56
+ // indicates the element also has `v-show`.
56
57
if ( vShowOriginalDisplay in el ) {
58
+ // make v-show respect the current v-bind style display when shown
57
59
el [ vShowOriginalDisplay ] = hasControlledDisplay ? style . display : ''
58
- style . display = currentDisplay
60
+ // if v-show is in hidden state, v-show has higher priority
61
+ if ( ( el as VShowElement ) [ vShowHidden ] ) {
62
+ style . display = 'none'
63
+ }
59
64
}
60
65
}
61
66
0 commit comments