jigDatepicker closes modal #11
-
hello ! i am implementing a modal form, and there are 2 fields with date format i would appreciate any suggestions regards, |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 5 replies
-
Hello guys! can anyone take a look at this issue, please? regards, |
Beta Was this translation helpful? Give feedback.
-
Hi @mquevedob , |
Beta Was this translation helpful? Give feedback.
-
the normal behavior of the modal is that if you click elsewhere, it closes |
Beta Was this translation helpful? Give feedback.
-
You are actually right, the datepicker is considered outside the modal because it is actually attached to the body. Now I remember I experienced this challenge once. I can only give you a work-around for it: Configure this particular modal so that it is static (Does not close when you click outside). |
Beta Was this translation helpful? Give feedback.
-
On Further evaluation, I have noticed that https://headlessui.dev/vue/dialog static option does not work as long as you have passed the onClose event to Dialog. As a work around, I have made the following modification and added a static prop to JigModal component. Now the component will check if static is true before calling the toggleModal method. If static is true, it will not close the modal. Just copy the code below and replace it in your js/JigComponents/JigModal.vue, then in your view that calls the dialog, simply pass the :static="true" prop to jig-modal. <template>
<TransitionRoot appear :show="isOpen" as="template">
<Dialog as="div" static :open="isOpen" @close="!static && toggleModal(false)">
<div class="fixed inset-0 z-50 overflow-y-auto">
<div class="min-h-screen px-4 text-center">
<TransitionChild
as="template"
enter="duration-300 ease-out"
enter-from="opacity-0"
enter-to="opacity-75"
leave="duration-200 ease-in"
leave-from="opacity-75"
leave-to="opacity-0"
>
<DialogOverlay
class="fixed inset-0 bg-gray-900 bg-opacity-60"
/>
</TransitionChild>
<span
class="inline-block h-screen align-middle"
aria-hidden="true"
>
​
</span>
<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"
>
<div
class="inline-block w-full p-6 my-8 overflow-hidden text-left transition-all transform bg-white shadow-xl "
:class="`${cornerClass} ${positionClass} ${maxWidthClass}`"
>
<DialogTitle
as="h3"
class="flex items-center justify-between text-lg font-medium leading-6 text-gray-900 "
>
<span class="flex-1"
>TITLE <slot name="title"></slot
></span>
<button
type="button"
class="p-1 px-2"
@click="toggleModal(false)"
>
<i
class="font-bold text-red-500 fas fa-times"
></i>
</button>
</DialogTitle>
<div class="mt-2">
<slot name="default"></slot>
</div>
<div class="mt-4 space-x-2 text-right">
<slot name="footer"></slot>
</div>
</div>
</TransitionChild>
</div>
</div>
</Dialog>
</TransitionRoot>
</template>
<script>
import { ref, defineComponent } from "vue";
import {
TransitionRoot,
TransitionChild,
Dialog,
DialogOverlay,
DialogTitle,
} from "@headlessui/vue";
export default defineComponent({
name: "JigModal",
props: {
show: Boolean,
static: Boolean,
cornerClass: {
default: "rounded-2xl",
},
positionClass: {
default: "align-middle",
},
maxWidthClass: {
default: "max-w-2xl",
},
},
components: {
TransitionRoot,
TransitionChild,
Dialog,
DialogOverlay,
DialogTitle,
},
emits: ["close"],
setup(props, ctx) {
const isOpen = ref(true);
return {
isOpen,
toggleModal(open) {
isOpen.value = open;
if (!open) {
ctx.emit("close");
}
},
};
},
watch: {
show(val) {
this.toggleModal(val);
},
},
});
</script>
|
Beta Was this translation helpful? Give feedback.
On Further evaluation, I have noticed that https://headlessui.dev/vue/dialog static option does not work as long as you have passed the onClose event to Dialog. As a work around, I have made the following modification and added a static prop to JigModal component. Now the component will check if static is true before calling the toggleModal method. If static is true, it will not close the modal. Just copy the code below and replace it in your js/JigComponents/JigModal.vue, then in your view that calls the dialog, simply pass the :static="true" prop to jig-modal.
This should work, I have tested it locally.
JigModal.vue