5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-23 04:46:21 +00:00

feat: poder ocultar con un evento también

This commit is contained in:
f 2024-05-18 18:48:49 -03:00
parent 71a15ae693
commit 8cafe32ce7
No known key found for this signature in database

View file

@ -6,13 +6,16 @@ export default class extends Controller {
// TODO: Stimulus >1 // TODO: Stimulus >1
connect() { connect() {
this.showEvent = this.show.bind(this); this.showEvent = this.show.bind(this);
this.hideEvent = this.hide.bind(this);
window.addEventListener("modal:show", this.showEvent); window.addEventListener("modal:show", this.showEvent);
window.addEventListener("modal:hide", this.hideEvent);
} }
// TODO: Stimulus >1 // TODO: Stimulus >1
disconnect() { disconnect() {
window.removeEventListener("modal:show", this.showEvent); window.removeEventListener("modal:show", this.showEvent);
window.removeEventListener("modal:hide", this.hideEvent);
} }
/* /*
@ -41,6 +44,9 @@ export default class extends Controller {
hide(event = undefined) { hide(event = undefined) {
event?.preventDefault(); event?.preventDefault();
const modalId = event?.detail?.id;
if (modalId && this.element.id !== modalId) return;
this.backdropTarget.classList.remove("show"); this.backdropTarget.classList.remove("show");
this.modalTarget.classList.remove("show"); this.modalTarget.classList.remove("show");