Jenesius / vue-modal

🖖The progressive and simple modal system for Vue.js v3
https://modal.jenesius.com
MIT License
150 stars 14 forks source link

prevent close when click outside #49

Closed morteza-mortezai closed 2 years ago

morteza-mortezai commented 2 years ago

Hello,

I want to know if there is any way to prevent modal close when click modal outside .

I know I can prevent it like below but it is not good for me because I want to close it with emmited event and this can't do that

  modal.onclose = () => {
    return false;
  }

is there any way ?

Jenesius commented 2 years ago

@morteza-mortezai Hi. If it needed right now, u can use config:

import {config} from "jenesius-vue-modal";

config({
    backgroundClose: false
})

But it will added to all modals. Or, give me one day, i will add it the same functional just for one modal in library

Jenesius commented 2 years ago

Also, if u will use config without adding to all modals backgroundClose key, u can try it :

mounted() {
  config({
    backgroundClose: false
})
},
unmounted() {
  config({
      backgroundClose: true
  })
}

but this is a quick fix - not pretty and doesn't respect modal logic

Jenesius commented 2 years ago

I will add the third parameter to openModal and pushModal

 openModal(Modal, {}, { backgroundClose: Boolean })
Jenesius commented 2 years ago

@morteza-mortezai Version 1.5.1

 openModal(Modal, {}, { backgroundClose: false })

or

const modal = await openModal(Modal);
modal.backgroundClose = false;
Jenesius commented 2 years ago

In future i will add event to onClose/beforeModalClose/onBeforeModalClose hooks:

modal.onclose = (e: ModalEvent) {
  if (e.background) return false; // Stop closing modal, if user click on background
}

I will create the task for it. Thnx you for making this library better!