Skip to content

Modal Component @after:enter event #4149

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

Open
robwdwd opened this issue May 14, 2025 · 6 comments · May be fixed by #4187
Open

Modal Component @after:enter event #4149

robwdwd opened this issue May 14, 2025 · 6 comments · May be fixed by #4187
Assignees
Labels
enhancement New feature or request triage v3 #1289

Comments

@robwdwd
Copy link

robwdwd commented May 14, 2025

Description

During creation of a flow diagram using vue-flow inside a modal there's an issue with the edge/connectors not lining up correctly and this is due to the transition/animation and to resolve the issue I need to recalculate the flow chart node positions after the transition/animation has ended.

I see there is a after:leave event but would be useful to have a 'after:enter' that fires off after the overlay/modal transitions/animations are finished.

I've tried using @animationed and @transitionend (they don't fire) and also update:open but that fires before the transition is done.

Additional context

As a workaround for now I'm listening the the update:open event and then setting a timer to wait for a bit then updating the nodes, which isn't ideal but work. Also turning of transitions on the model works.

<template>
  <ClientOnly>
    <UModal @update:open="toggleModelState">
      <UTooltip text="Open Modal.">
        <UButton icon="i-tabler-route-square-2" color="neutral" variant="ghost" class="float-right" />
      </UTooltip>
      <template #body>
        <div class="relative w-full h-[75vh]">
          <VueFlow v-if="isModalOpen" :nodes="nodes" :edges="edges" :nodes-connectable="nodesConnectable" @nodes-initialized="layoutGraph" />
        </div>
      </template>
    </UModal>
  </ClientOnly>
</template>

<script setup lang="ts">
import { ref, } from 'vue';
import { useVueFlow, type Edge, type Node } from '@vue-flow/core'

const config = useRuntimeConfig();

// Define the props with TypeScript
const { treeData } = defineProps<{
  treeData: Array<Array<number>>;
  prefix: string;
}>();

const nodesConnectable = ref(false)
const isModalOpen = ref(false)
const hasParsedPaths = ref(false); // Flag to track if paths have been parsed

const nodes = ref<Node[]>([]);
const edges = ref<Edge[]>([]);
const { layout } = useLayout();
const { fitView, updateNodeInternals } = useVueFlow();

function toggleModelState(event: boolean) {
  if (event === true) {
    // Workaround to fix issue with connectors/edges after transition has finisehd
    //
    setTimeout(() => {
      updateNodeInternals(); // re-calculate node positions
    }, 250);
  }
  isModalOpen.value = event;
}

async function layoutGraph(): Promise<void> {
  nodes.value = layout(nodes.value, edges.value);
  await nextTick(() => {
    fitView();
  });
}
</script>

@robwdwd robwdwd added enhancement New feature or request v3 #1289 triage labels May 14, 2025
@benjamincanac
Copy link
Member

@genu Since you implemented the @after:leave event, maybe you have some hints about this?

@genu genu self-assigned this May 18, 2025
@genu
Copy link
Member

genu commented May 19, 2025

@robwdwd If I recall, vue-flow generally requires parent container to have a width and a height. Have you tried wrapping it in a div which has width and height?

In my testing, if I do something like this:

<div class="w-[300px] border h-[300px]">
    <VueFlow :nodes="nodes" :edges="edges"/>
</div>

it works with no problem.

I'm also not able to run your sample code above. where is useLayout() coming from?

If possible, please create a minimal repro with the issue for me to be able to look into this in depth.

Copy link

Would you be able to provide a reproduction? 🙏

More info

Why do I need to provide a reproduction?

Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making.

What will happen?

If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritise it based on its severity and how many people we think it might affect.

If needs reproduction labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), they will be closed automatically after a while. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it.

How can I create a reproduction?

We have templates to create a minimal reproduction:

Please ensure that the reproduction is as minimal as possible. See more details in our guide.

You might also find these other articles interesting and/or helpful:

@robwdwd
Copy link
Author

robwdwd commented May 19, 2025

@genu - The specific issue was described here

bcakmakoglu/vue-flow#1365

In particular.

bcakmakoglu/vue-flow#1365 (reply in thread)

Width and Height are already done here.

<div class="relative w-full h-[75vh]">

I’ll try and create a reproduction tomorrow for you.

@genu genu linked a pull request May 19, 2025 that will close this issue
8 tasks
@genu
Copy link
Member

genu commented May 19, 2025

@robwdwd If you can, can you test this PR: #4187

it exposes a after-enter event on the UModal that you can use to call updateNodeInternals()

@robwdwd
Copy link
Author

robwdwd commented May 21, 2025

@genu - Great, that works perfectly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage v3 #1289
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants