Replies: 2 comments 5 replies
-
I made a workaround for me. In parent component I register JavaScript hooks and define them as: function callHook(el: Element, hook: string) {
if ("__vue_exposed" in el) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const exposed = el.__vue_exposed as Record<string, any> | null
if (exposed && hook in exposed) {
exposed[hook]()
}
}
}
function onAfterEnter(el: Element) {
callHook(el, "onAfterEnter")
}
function onEnterCancelled(el: Element) {
callHook(el, "onEnterCancelled")
}
function onBeforeLeave(el: Element) {
callHook(el, "onBeforeLeave")
}
function onLeave(el: Element) {
callHook(el, "onLeave")
}
function onAfterLeave(el: Element) {
callHook(el, "onAfterLeave")
}
function onLeaveCancelled(el: Element) {
callHook(el, "onLeaveCancelled")
} In child components I do:
And then the child component can do: defineExpose({
onAfterEnter() {
document.getElementById("form-field")?.focus()
},
}) This approach does not support |
Beta Was this translation helpful? Give feedback.
-
Partially related: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, when a component is inside a Transition component, component cannot easily know when the transition has finished and when it is fully shown to the user to do some followup changes.
So I would like that there are hooks inside
ComponentOne
andComponentTwo
which i could use to know how animations are progressing.Use case
I want to focus input box after transition finishes. If I call focus too early it can interfere with the animation (preventScroll is sadly not supported on all browsers).
Workaround
One can add
@transitionend
and/or@animationend
event handler(s) on the top element of the component, but that is fragile because component should not care if it is wrapped in Transition component or not, or if the Transition component is using animation or transitions. Maybe Transition is not using CSS to animate at all.Precedence
KeepAlive built-in component calls onActivated/onDeactivated life-cycle hooks.
Suggestion
I would suggest that Transition also calls onLeaveTransition (before DOM element is transitioned out) and
onEnterTransition
(after DOM element is transitioned in) life-cycle hooks.Alternatively, a full set of hooks could be exposed:
Currently those hooks are available on parent component, but not on child components. Having them on child components would make it possible to have children respond to animations as well.
Beta Was this translation helpful? Give feedback.
All reactions