fix(v-show): v-show takes higher priority than style attribute (#3230)

fix #2757
This commit is contained in:
HcySunYang
2021-02-25 23:26:54 +08:00
committed by GitHub
parent 45fae9d308
commit 5ad4036e29
3 changed files with 72 additions and 3 deletions

View File

@@ -3,9 +3,11 @@ import {
defineComponent,
h,
nextTick,
VNode
VNode,
ref,
watch
} from '@vue/runtime-core'
import { render, vShow } from '@vue/runtime-dom'
import { render, Transition, vShow } from '@vue/runtime-dom'
const withVShow = (node: VNode, exp: any) =>
withDirectives(node, [[vShow, exp]])
@@ -124,4 +126,63 @@ describe('runtime-dom: v-show directive', () => {
await nextTick()
expect($div.style.display).toEqual('block')
})
// #2583
test('the value of `display` set by v-show should not be overwritten by the style attribute when updated', async () => {
const style = ref('width: 100px')
const display = ref(false)
const component = defineComponent({
render() {
return withVShow(h('div', { style: style.value }), display.value)
}
})
render(h(component), root)
const $div = root.querySelector('div')
expect($div.style.display).toEqual('none')
style.value = 'width: 50px'
await nextTick()
expect($div.style.display).toEqual('none')
display.value = true
await nextTick()
expect($div.style.display).toEqual('')
})
// #2583, #2757
test('the value of `display` set by v-show should not be overwritten by the style attribute when updated (with Transition)', async () => {
const style = ref('width: 100px')
const display = ref(false)
const component = defineComponent({
setup() {
const innerValue = ref(false)
watch(display, val => {
innerValue.value = val
})
return () => {
return h(Transition, () =>
withVShow(
h('div', { style: style.value }, innerValue.value),
display.value
)
)
}
}
})
render(h(component), root)
const $div = root.querySelector('div')
expect($div.style.display).toEqual('none')
style.value = 'width: 50px'
await nextTick()
expect($div.style.display).toEqual('none')
display.value = true
await nextTick()
expect($div.style.display).toEqual('')
})
})