Component not firing events in some render hooks

I have the following render hook set up in the boot method in: app/Providers/Filament/AdminPanelProvider.php
FilamentView::registerRenderHook(
'panels::global-search.before',
fn (): string => Blade::render('@livewire(\'publish-staff-button\')'),
);
FilamentView::registerRenderHook(
'panels::global-search.before',
fn (): string => Blade::render('@livewire(\'publish-staff-button\')'),
);
This renders a simple component in: resources/views/livewire/publish-staff-button.blade.php
<x-filament::button wire:click="$dispatch('publish-staff')">
Publish
</x-filament::button>
<x-filament::button wire:click="$dispatch('publish-staff')">
Publish
</x-filament::button>
With the following method in the component class: app/Livewire/PublishStaffButton.php
#[On('publish-staff')]
public function publishStaff(): void
{
// Do something...
}
#[On('publish-staff')]
public function publishStaff(): void
{
// Do something...
}
Now if the render hook is in 'panels::global-search.start' then it will work but messes up the global search results (no idea why) but if it is in 'global-search.before' no events are fired. Any ideas?
Solution:
ok, so I have managed to get it working by just wrapping the button in a div, it seems as though it doesn't work when it is the root element!? ``` <div> <x-filament::button wire:click="publishStaff"> {{$label}}...
Jump to solution
2 Replies
Matt Jenkins
Matt Jenkins7mo ago
Also, I have no idea why I have to dispatch an event at all, i would have thought I could just use wire:click='publishStaff' from the component but this seems to be called agains the x-filament::button itself
Solution
Matt Jenkins
Matt Jenkins7mo ago
ok, so I have managed to get it working by just wrapping the button in a div, it seems as though it doesn't work when it is the root element!?
<div>
<x-filament::button wire:click="publishStaff">
{{$label}}
</x-filament::button>
</div>
<div>
<x-filament::button wire:click="publishStaff">
{{$label}}
</x-filament::button>
</div>