Skip to content

Commit

Permalink
Fix event duplication when using wire:navigate
Browse files Browse the repository at this point in the history
  • Loading branch information
PhiloNL committed Dec 8, 2023
1 parent d6dac3a commit 899b05e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"require": {
"php": "^8.1",
"livewire/livewire": "^3.0",
"livewire/livewire": "^3.2.3",
"spatie/laravel-package-tools": "^1.9"
},
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion public/modal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions resources/js/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ window.LivewireUIModal = () => {
activeComponent: false,
componentHistory: [],
modalWidth: null ,
listeners: [],
getActiveComponentModalAttribute(key) {
if (this.$wire.get('components')[this.activeComponent] !== undefined) {
return this.$wire.get('components')[this.activeComponent]['modalAttributes'][key];
Expand Down Expand Up @@ -140,12 +141,21 @@ window.LivewireUIModal = () => {
init() {
this.modalWidth = this.getActiveComponentModalAttribute('maxWidthClass');

Livewire.on('closeModal', (data) => {
this.closeModal(data?.force ?? false, data?.skipPreviousModals ?? 0, data?.destroySkipped ?? false);
});

Livewire.on('activeModalComponentChanged', ({id}) => {
this.setActiveModalComponent(id);
this.listeners.push(
Livewire.on('closeModal', (data) => {
this.closeModal(data?.force ?? false, data?.skipPreviousModals ?? 0, data?.destroySkipped ?? false);
})
);

this.listeners.push(
Livewire.on('activeModalComponentChanged', ({id}) => {
this.setActiveModalComponent(id);
})
);
},
destroy() {
this.listeners.forEach((listener) => {
listener();
});
}
};
Expand Down

0 comments on commit 899b05e

Please sign in to comment.