FilamentF
Filament2y ago
Ron

How to close an ActionGroup dropdown with a custom function after the function completes

I see from a similar post how to close the drop down immediately on click, but is there a way to close the drop down within the custom function itself to preserve the progress spinner on the action?

The code below shows an action w/in a group where the drop down is closed immediately (this code was from a similar post)
ActionGroup::make([
  Action::make('process')
                   ->action(function (Action $action) {
                        // ... run process function
                        // Is it possible to use the injected Action to close here, after processing
                    })
                    // Adding Extra Attributes will close the drop down immediately
                    ->extraAttributes(['x-on:click' => 'close']),
])->button();
Solution
Its a bit similar:

Here is an example code:

      ActionGroup::make([
        Action::make('test')
          ->action(fn() => $v = "do something")
          ->after(fn($livewire)=> 
              $livewire->dispatch('close-menu')),
        ])->extraAttributes([
              "x-on:close-menu.window" => <<<JS
                        close();
                    JS
        ])
Was this page helpful?