Replies: 5 comments 9 replies
-
Hi! You can use stopPropagation Try adding the following onClick event to your Toast/Toaster component to prevent it from triggering the Dialog onClose handler:
Hope it helps! 👍 |
Beta Was this translation helpful? Give feedback.
-
I had exactly the same issue. Calling stopPropagation doesn't work because sequence of events when clicking on the toast is:
To make it work I did the following:
|
Beta Was this translation helpful? Give feedback.
-
@dd-jonas I think I found a solution to this problem. HeadlessUI provides a
It would not close the |
Beta Was this translation helpful? Give feedback.
-
@dd-jonas Here's the solution I came up with yesterday. Hope it's helpful! There is likely a more "React way" of doing this, but here's what I've done for now.
|
Beta Was this translation helpful? Give feedback.
-
I found that there is another way of bypassing this issue, I use Vue3 therefore component looks slightly different. Now don't forget to put your Here is my Vue3 component: <template>
<TransitionRoot appear :show="true" as="template">
<Dialog as="div" class="relative z-30">
<TransitionChild
as="template"
enter="duration-300 ease-out"
enter-from="opacity-0"
enter-to="opacity-100"
leave="duration-200 ease-in"
leave-from="opacity-100"
leave-to="opacity-0"
>
<div class="fixed inset-0 bg-black/25" />
</TransitionChild>
<div
@click="$emit('closeModal')" <--- HERE
class="fixed inset-0 overflow-y-auto bg-gray-500 bg-opacity-75 transition-opacity"
>
<div
class="flex min-h-full items-center justify-center p-4 text-center"
>
<TransitionChild
as="template"
enter="duration-300 ease-out"
enter-from="opacity-0 scale-95"
enter-to="opacity-100 scale-100"
leave="duration-200 ease-in"
leave-from="opacity-100 scale-100"
leave-to="opacity-0 scale-95"
>
<DialogPanel
class="w-full max-w-md transform overflow-hidden rounded-2xl bg-white dark:bg-slate-800 p-6 text-left align-middle shadow-xl transition-all"
>
<DialogTitle
as="h3"
class="text-lg mt-4 font-medium leading-6 dark:text-slate-200 text-slate-900"
>
{{
$t(
"platform.memberships.delete_membership_confirmation_title",
)
}}
</DialogTitle>
<div class="mt-2">
<p class="text-sm dark:text-slate-400 text-slate-500">
{{
$t(
"platform.memberships.delete_membership_confirmation_text",
)
}}
</p>
</div>
<div class="mt-6 flex justify-between">
<BaseButton
:button-theme="themeButtonService.getThemeButtonById(5)"
:disabled="submitInProgress"
class="font-bold"
@click="$emit('closeModal')"
>
{{ $t("global.cancel") }}
</BaseButton>
<BaseButton
:button-theme="themeButtonService.getThemeButtonById(8)"
:disabled="submitInProgress"
class="font-bold"
@click="$emit('deleteMembership')"
>
<BaseSpinnerSmall
:submit-in-progress="submitInProgress"
spinner-text="global.deleting"
button-text="global.delete"
/>
</BaseButton>
</div>
</DialogPanel>
</TransitionChild>
</div>
</div>
</Dialog>
</TransitionRoot>
</template>
<script setup lang="ts">
import {
TransitionRoot,
TransitionChild,
Dialog,
DialogPanel,
DialogTitle,
} from "@headlessui/vue";
import { themeButtonService } from "~/services/theme/ThemeButtonService";
interface Props {
submitInProgress: boolean;
}
defineProps<Props>();
defineEmits(["closeModal", "deleteMembership"]);
</script> Here is how I specified my ToastMessage: <template>
<div>
<Portal class="z-50">
<ModalMessage />
<ToastMessage />
</Portal>
<TheSidebar :sidebar-open="sidebarOpen" @toggle-sidebar="toggleSidebar" />
<TheTopbar :sidebar-open="sidebarOpen" @toggle-sidebar="toggleSidebar" />
<div class="xl:pl-72">
<slot class="bg-slate-100 dark:bg-slate-900"></slot>
</div>
</div>
</template>
<script setup lang="ts">
import { Portal } from "@headlessui/vue";
import TheSidebar from "@/components/platform/sidebar/TheSidebar.vue";
import TheTopbar from "@/components/platform/topbar/TheTopbar.vue";
// This import is here to make sure the proper theme is set
// when reloading one of the Auth pages
import { themeColorService } from "~/services/theme/ThemeColorService";
import ToastMessage from "~/components/response/ToastMessage.vue";
import ModalMessage from "~/components/response/ModalMessage.vue";
themeColorService.getTheme();
const sidebarOpen = ref(false);
function toggleSidebar() {
sidebarOpen.value = !sidebarOpen.value;
}
</script> |
Beta Was this translation helpful? Give feedback.
-
Hey, I was wondering what the best way is to prevent the dialog closing when clicking a toast message.
Since the toasts appear on top of the dialog container, it doesn't make much sense that clicking it triggers the onClose of the dialog. Ideally I only want the dialog to trigger a 'click outside' event when clicking the overlay. Is there a way to achieve this?
Maybe relevant: I'm using React Toastify for the toast messages. This renders a container next to my app inside the root container, which is before the Headless UI container in the DOM order.
Beta Was this translation helpful? Give feedback.
All reactions