Skip to content
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

[v3][UModal] Modal programatically opened using useModal are not reseting its state after close #2777

Open
hamonCordova opened this issue Nov 26, 2024 · 6 comments · May be fixed by #3279
Open
Labels
bug Something isn't working v3 #1289

Comments

@hamonCordova
Copy link

Environment



Is this bug related to Nuxt or Vue?

Nuxt

Version

^3.0.0-alpha.9

Reproduction

https://ui3.nuxt.dev/components/modal#programmatic-usage

Description

Modal opened using useModal are not reseting its state after close

Additional context

No response

Logs

@hamonCordova hamonCordova added bug Something isn't working triage v3 #1289 labels Nov 26, 2024
@clopezpro
Copy link
Contributor

Exactly I had to use something like this. I think it is the action of the close button that is added by default that does not change the state of v-model:open
Image

Copy link
Member

@noook Any hint on this?

@benjamincanac benjamincanac removed the triage label Nov 28, 2024 — with Volta.net
@clopezpro
Copy link
Contributor

I’ve been testing this, and if we want to use a modal with useModal, we can’t do something like this:

Image
This is because useModal exports a reactive variable isOpen that globally controls the currently opened modal.
Image
so it is working as it should
https://github.com/user-attachments/assets/3e7fcd97-a92a-4de5-b93e-ce672738c414

@ghost
Copy link

ghost commented Dec 9, 2024

using modal.isOpen.value or modal.close() programmatically does not trigger the update:open event in my testing

@dustin-we
Copy link

I am having the same issue. Opening a modal with:

const bookingModal = useModal();

bookingModal.open(ModalNewBooking, {
    context: ...
    onSuccess: ...
});

In v2, clicking outside the modal would reset it's state. When opening the modal again, the setup function would re-run.

In v3, the setup function is not re-run, resulting in, e.g., the modal's form being filled with data from the previous modal's form.

A workaround is closing the modal via useModal().reset() from inside or outside the modal component itself. But then, the modal cannot be dismissible, because clicking outside of the modal won't trigger the reset, so you need to use 'your own' close-button.

Example:

<UModal
    title="test"
    :dismissible="false"
>
    <template #close>
        <UButton @click="useModal().reset()">Close</UButton>
      </template>
...
</UModal>

@xergic
Copy link

xergic commented Jan 17, 2025

My workaround is this:

watch(modal.isOpen, (value) => {
  if (!value) {
    modal.reset()
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v3 #1289
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants