F
Filamentβ€’6mo ago
ericmp

Disable action with tooltip

I want to show the reason why the action is disabled. But if i disable it, the tooltip isn't shown. What would u do? I don't want to make the action to be enabled just to show the tooltip. I want it not to be clickable but hoverable to be able to see the tooltip.
6 Replies
dissto
disstoβ€’6mo ago
Here is one quick and dirty solution: Just bail out. Im afraid otherwise you would need a custom view for the action where you wrap the trigger in another element. See this comment
Tables\Actions\Action::make('dummy')
->tooltip('sdfsdf')
->extraAttributes(['class' => 'opacity-70 cursor-not-allowed'])
->before(function (Tables\Actions\Action $action) {
$action->cancel();
}),
Tables\Actions\Action::make('dummy')
->tooltip('sdfsdf')
->extraAttributes(['class' => 'opacity-70 cursor-not-allowed'])
->before(function (Tables\Actions\Action $action) {
$action->cancel();
}),
ericmp
ericmpOPβ€’6mo ago
lol u wont believe it just 2 seconds ago, when u modified the msg to add it, i added that class too but if i have requiresConfirmation() it shows up the modal anyways πŸ€”
dissto
disstoβ€’6mo ago
requiresConfirmation accepts a closure too, so whatever your reason is to disable can be applied to that too i suppose
ericmp
ericmpOPβ€’6mo ago
maybe modifying requires confirmation closure yeah let me try 😫 but im on a DeleteAction, lets dig into it and see how to handle it oh, its just requiresConfirmation, ez, i override it i guess all this changes could be wrapped in a new fn called disabledWithTooltip that would be a trait like the requires confirmation one but with the changes u shared me instead
trait CanRequireConfirmation
{
public function requiresConfirmation(bool | Closure $condition = true): static
{
$this->modalSubheading(fn (Action $action): ?string => $action->evaluate($condition) ? __('filament-support::actions/modal.confirmation') : null);
$this->modalButton(fn (Action $action): ?string => $action->evaluate($condition) ? __('filament-support::actions/modal.actions.confirm.label') : null);
$this->modalWidth(fn (Action $action): ?string => $action->evaluate($condition) ? 'sm' : null);
$this->centerModal($condition);

return $this;
}
}
trait CanRequireConfirmation
{
public function requiresConfirmation(bool | Closure $condition = true): static
{
$this->modalSubheading(fn (Action $action): ?string => $action->evaluate($condition) ? __('filament-support::actions/modal.confirmation') : null);
$this->modalButton(fn (Action $action): ?string => $action->evaluate($condition) ? __('filament-support::actions/modal.actions.confirm.label') : null);
$this->modalWidth(fn (Action $action): ?string => $action->evaluate($condition) ? 'sm' : null);
$this->centerModal($condition);

return $this;
}
}
so yeah it works, thanks for the help @dissto
dissto
disstoβ€’6mo ago
actions are `macroable' so its fair game to add a macro...if you were to use a trait you would need to extend an action πŸ€“
ericmp
ericmpOPβ€’6mo ago
i tought more of a built in filament feature, ill checkout the github link u shared me, maybe i can try a PR @dissto what do u think xd https://github.com/filamentphp/filament/discussions/4271#discussioncomment-10125186
Want results from more Discord servers?
Add your server