@@ -3,9 +3,11 @@ import {
3
3
defineComponent ,
4
4
h ,
5
5
nextTick ,
6
- VNode
6
+ VNode ,
7
+ ref ,
8
+ watch
7
9
} from '@vue/runtime-core'
8
- import { render , vShow } from '@vue/runtime-dom'
10
+ import { render , Transition , vShow } from '@vue/runtime-dom'
9
11
10
12
const withVShow = ( node : VNode , exp : any ) =>
11
13
withDirectives ( node , [ [ vShow , exp ] ] )
@@ -124,4 +126,63 @@ describe('runtime-dom: v-show directive', () => {
124
126
await nextTick ( )
125
127
expect ( $div . style . display ) . toEqual ( 'block' )
126
128
} )
129
+
130
+ // #2583
131
+ test ( 'the value of `display` set by v-show should not be overwritten by the style attribute when updated' , async ( ) => {
132
+ const style = ref ( 'width: 100px' )
133
+ const display = ref ( false )
134
+ const component = defineComponent ( {
135
+ render ( ) {
136
+ return withVShow ( h ( 'div' , { style : style . value } ) , display . value )
137
+ }
138
+ } )
139
+ render ( h ( component ) , root )
140
+
141
+ const $div = root . querySelector ( 'div' )
142
+
143
+ expect ( $div . style . display ) . toEqual ( 'none' )
144
+
145
+ style . value = 'width: 50px'
146
+ await nextTick ( )
147
+ expect ( $div . style . display ) . toEqual ( 'none' )
148
+
149
+ display . value = true
150
+ await nextTick ( )
151
+ expect ( $div . style . display ) . toEqual ( '' )
152
+ } )
153
+
154
+ // #2583, #2757
155
+ test ( 'the value of `display` set by v-show should not be overwritten by the style attribute when updated (with Transition)' , async ( ) => {
156
+ const style = ref ( 'width: 100px' )
157
+ const display = ref ( false )
158
+ const component = defineComponent ( {
159
+ setup ( ) {
160
+ const innerValue = ref ( false )
161
+ watch ( display , val => {
162
+ innerValue . value = val
163
+ } )
164
+ return ( ) => {
165
+ return h ( Transition , ( ) =>
166
+ withVShow (
167
+ h ( 'div' , { style : style . value } , innerValue . value ) ,
168
+ display . value
169
+ )
170
+ )
171
+ }
172
+ }
173
+ } )
174
+ render ( h ( component ) , root )
175
+
176
+ const $div = root . querySelector ( 'div' )
177
+
178
+ expect ( $div . style . display ) . toEqual ( 'none' )
179
+
180
+ style . value = 'width: 50px'
181
+ await nextTick ( )
182
+ expect ( $div . style . display ) . toEqual ( 'none' )
183
+
184
+ display . value = true
185
+ await nextTick ( )
186
+ expect ( $div . style . display ) . toEqual ( '' )
187
+ } )
127
188
} )
0 commit comments