Skip to content

Commit

Permalink
Dispatch an event to a modal being closed before closing it, so that …
Browse files Browse the repository at this point in the history
…the modal can prevent it based on its state
  • Loading branch information
osmianski committed Sep 16, 2024
1 parent 17b6159 commit 2f97bbe
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions resources/js/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ window.LivewireUIModal = () => {
return;
}

if (!this.closingModal('closingModalOnEscape')) {
return;
}

let force = this.getActiveComponentModalAttribute('closeOnEscapeIsForceful') === true;
this.closeModal(force);
},
Expand All @@ -24,8 +28,24 @@ window.LivewireUIModal = () => {
return;
}

if (!this.closingModal('closingModalOnClickAway')) {
return;
}

this.closeModal(true);
},
closingModal(eventName) {
const componentName = this.$wire.get('components')[this.activeComponent].name;

var params = {
id: this.activeComponent,
closing: true,
};

Livewire.dispatchTo(componentName, eventName, params);

return params.closing;
},
closeModal(force = false, skipPreviousModals = 0, destroySkipped = false) {
if(this.show === false) {
return;
Expand Down

0 comments on commit 2f97bbe

Please sign in to comment.