Jenesius / vue-modal

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

Gaurd return false.Modal navigation was stoped. #92

Closed RezaErfani67 closed 9 months ago

RezaErfani67 commented 10 months ago

hi if i click outside of modal, it close correctly... but if i press ESC, it gives me error...

here is my code


async function modalForAdd(){
const modal = await pushModal(MyModal , Props);
....
}
modal.onclose(event) =>{
if(event.background) return false;
if(event.esc) return false;
}
anshirko commented 10 months ago

@RezaErfani67 Yep, I also encountered this problem. After check the library I found the next line:

document.addEventListener("keyup", e => {
        // Closing the last modal window when user pressed Escape
        if (configuration.escClose && (e.key === "Escape" || e.code === "Escape")) {
            const modal = getCurrentModal();
            if (!modal) return;
            closeById(modal.id, {esc: true}) // THIS LINE!
        }
    })

After change adding .catch everything work fine!

So, my solutiton:

import {config, closeById, getCurrentModal} from "jenesius-vue-modal";

config({
  escClose: false // Turn off default closing 
})
document.addEventListener("keyup", e => {
        // Closing the last modal window when user pressed Escape
        if (e.key === "Escape" || e.code === "Escape") {
            const modal = getCurrentModal();
            if (!modal) return;
            closeById(modal.id, {esc: true}).catch(() => {})
        }
    })

But it definitely needs to be discussed with the library developer.

Jenesius commented 10 months ago

@RezaErfani67, thnx for notify about bug! The solution presented by @anshirko should work, but it should be fixed inside library. I will update version tomorrow and notify here!

RezaErfani67 commented 10 months ago

thanks alot @anshirko @Jenesius

Jenesius commented 10 months ago

@RezaErfani67 Package version 1.9.3.