FilamentF
Filament11mo ago
Nijholt

HeaderAction disappears after usage.

I've got this action:

<?php

declare(strict_types=1);

namespace App\Filament\Components\HeaderActions;

use App\Models\Status;
use Filament\Actions\Action;

class PublicationStatusAction extends Action
{
    protected function setUp(): void
    {
        parent::setUp();

        $this
            ->view('filament.actions.publication-status')
            ->hidden(false);
    }

    public static function make(?string $name = null): static
    {
        return parent::make($name);
    }

    public function getOptions(): array
    {
        return [
            'published'   => __('status_action.' . Status::STATUS_PUBLISHED),
            'unpublished' => __('status_action.' . Status::STATUS_UNPUBLISHED),
        ];
    }

    public function getSelected(): string
    {
        return $this->getRecord()->status?->key ?? '';
    }
}


With view:
<x-filament::input.wrapper>
    <x-filament::input.select
        x-on:change="$wire.updateStatus($event.target.value)"
        class="fi-select-input"
    >
        @foreach ($getOptions() as $value => $label)
            <option value="{{ $value }}" @if ($value === $getSelected()) selected @endif>
                {{ $label }}
            </option>
        @endforeach
    </x-filament::input.select>
</x-filament::input.wrapper>


Code works, but after change, the components gets detached. How to prevent the action from disappearing from the header actions?
Was this page helpful?