-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Transition component does not work with “visibility” #2531
Comments
It's very easy to add a modifier like |
For the benefit of anyone else reading this, there is a corresponding Stack Overflow question here: I believe this is really a feature request rather than a bug report. Currently it is possible to hide an element in a transition-safe way using |
Thanks @skirtles-code ! Really helpful solution on the Stack Overflow.
Yeah, absolutely right. Or may be it could be a strategy function something like this. <template>
<div v-show:strategy="setDisplay">foobar</div>
</template>
<script lang="ts">
interface ElementDisplay {
new(el: HTMLElement): void
show()
hide()
}
class VisibilityStrategy implements ElementDisplay {
private el: HTMLElement;
constructor(el: HTMLElement) {
this.el = el
}
show() {
this.el.style.visibility = 'visible'
this.el.style.opacity = '1'
this.el.classList.remove('is-hidden')
}
hide() {
this.el.style.visibility = 'hidden'
this.el.style.opacity = '0'
this.el.classList.add('is-hidden')
}
}
export default {
data() {
return {
setDisplay: VisibilityStrategy
}
}
}
</script> then this function can be replaced by the But a simple |
I would like to implement it, make transition component can effect on |
I find that this issue should be added a Suppose the user-defined direcitve looks like following(similar to const visibility = {
beforeMount(el, { value }, { transition }) {
el._vod = el.style.visibility === '' ? 'hidden' : el.style.visibility
if (transition && value) {
transition.beforeEnter(el)
} else {
el.style.visibility = value || 'hidden'
}
},
updated(el, { value, oldValue }, { transition }) {
if (!value === !oldValue) {
return
}
if (value) {
// step 1
transition.beforeEnter(el)
el.style.visibility = 'visible'
// step 2
transition.enter(el)
} else {
transition.leave(el, () => {
el.style.visibility = 'hidden'
})
}
}
} The following code is part of Transition.ts. // step 1: transition.beforeEnter
onBeforeEnter(el) {
onBeforeEnter && onBeforeEnter(el)
// add *-enter-active
addTransitionClass(el, enterActiveClass)
// add *-enter-from
addTransitionClass(el, enterFromClass)
} // step 2: transition.enter
const makeEnterHook = (isAppear: boolean) => {
return (el: Element, done: () => void) => {
const hook = isAppear ? onAppear : onEnter
const resolve = () => finishEnter(el, isAppear, done)
hook && hook(el, resolve)
nextFrame(() => {
// remove *-enter-from
removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass)
// add *-enter-to
addTransitionClass(el, isAppear ? appearToClass : enterToClass)
if (!(hook && hook.length > 1)) {
if (enterDuration) {
setTimeout(resolve, enterDuration)
} else {
whenTransitionEnds(el, type, resolve)
}
}
})
}
} // step 3: transition end
const finishEnter = (el: Element, isAppear: boolean, done?: () => void) => {
// remove *-enter-to
removeTransitionClass(el, isAppear ? appearToClass : enterToClass)
// remove *-enter-active
removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass)
done && done()
} We can see classes change processes:
Wait for confirmation and i can fix it. |
Disclaimer: I currently don't have a complete understanding of the transition mechanics in play here. That being said, I don't see why I should label this a bug when so far, we clearly only support The fact that you were not able to implement a custom directive with the existing internal APIs does not make an unsupported feature a bug. This still is, essentially, a feature request. |
OK, i see your point and it makes sense. |
…n the first frame (vuejs#2531, vuejs#2586)
Version
3.0.2
Reproduction link
https://codesandbox.io/s/competent-hermann-b1s5q
Steps to reproduce
see https://codesandbox.io/s/competent-hermann-b1s5q
What is expected?
The
transition
element of vue only works withdisplay:none
but notvisibility:hidden
.Is there any way to make it work with
visibility
?I want to get the
clientWidth
of the element before it shows up, withdisplay:none
I can't get that value.The text was updated successfully, but these errors were encountered: