filament icon indicating copy to clipboard operation
filament copied to clipboard

Show tooltip for disabled action button

Open ericmp33 opened this issue 1 year ago • 8 comments

Description

We would like to show a tooltip on a disabled action button to explain why that button is disabled. https://github.com/filamentphp/filament/discussions/4271

One thing to note is that this change might be an unexpected behavior for developers who previously had tooltips configured to display only when actions were enabled. We should consider mentioning this update in the What's Changed section of the release notes to avoid confusion.

Visual changes

If the action has a tooltip, despite being disabled, the tooltip will be shown.

Functional changes

  • [ ] Code style has been fixed by running the composer cs command.
  • [ ] Changes have been tested to not break existing functionality.
  • [x] Documentation is up-to-date.

ericmp33 avatar Jul 23 '24 12:07 ericmp33

Please test this by adding two buttons inside <div class="grid grid-cols-2"> and <div class="flex justify-end"> and <div class="flex justify-between">. Please screenshot each case and post them here, so we can review if there are any impacts of having a wrapper.

danharrin avatar Jul 24 '24 11:07 danharrin

Please test this by adding two buttons inside <div class="grid grid-cols-2"> and <div class="flex justify-end"> and <div class="flex justify-between">. Please screenshot each case and post them here, so we can review if there are any impacts of having a wrapper.

I created 3 different full page lw components with 2 action buttons per each. Both actions have tooltip, but one action is enabled and the other one is disabled (I also tried disabling it both actions, results look the same).

The class part looks the same for all 3. The view part changes on the classes used.

@danharrin is this what you expected me to try out?

https://github.com/user-attachments/assets/d768d216-4117-464f-8a12-db8530963b7d

Component classes:

<?php

namespace App\Livewire;

use App\View\Components\AppLayout;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Components\Actions;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Illuminate\Contracts\View\View;
use Livewire\Component;

class Test1 extends Component implements HasForms
{
    use InteractsWithForms;

    public function render(): View
    {
        return view('livewire.test1')->layout(AppLayout::class);
    }

    public function form(Form $form): Form
    {
        return $form->schema([
            Actions::make([
                Action::make('star')
                    ->icon('heroicon-m-star')
                    ->tooltip('First tooltip'),
                Action::make('resetStars')
                    ->icon('heroicon-m-x-mark')
                    ->color('danger')
                    ->tooltip('Second tooltip')
                    ->disabled(),
            ]),
        ]);
    }
}

Component views:

// test 1
<div class="grid grid-cols-2">
    {{ $this->form }}
</div>
// test 2
<div class="flex justify-end">
    {{ $this->form }}
</div>
// test 3
<div class="flex justify-between">
    {{ $this->form }}
</div>

ericmp33 avatar Jul 24 '24 17:07 ericmp33

is this what you expected

Probably is to directly using actions https://filamentphp.com/docs/3.x/actions/adding-an-action-to-a-livewire-component#adding-the-action

wychoong avatar Jul 24 '24 17:07 wychoong

is this what you expected

Probably is to directly using actions https://filamentphp.com/docs/3.x/actions/adding-an-action-to-a-livewire-component#adding-the-action

Oh yeah I see. Okay, I test it again.

ericmp33 avatar Jul 24 '24 18:07 ericmp33

New tests:

https://github.com/user-attachments/assets/d5230dc9-1d40-420e-b183-2e566728548c

Classes:

<?php

namespace App\Livewire;

use App\View\Components\AppLayout;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Components\Actions;
use Filament\Actions\Action;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Illuminate\Contracts\View\View;
use Livewire\Component;

class Test1 extends Component implements HasForms, HasActions
{
    use InteractsWithForms;
    use InteractsWithActions;

    public function render(): View
    {
        return view('livewire.test1')->layout(AppLayout::class);
    }

    public function oneAction(): Action
    {
        return Action::make('one')
            ->disabled()
            ->tooltip('One');
    }

    public function twoAction(): Action
    {
        return Action::make('two')
            // ->disabled()
            ->tooltip('Two');
    }
}

Views:

// test 1
<div class="grid grid-cols-2">
    {{ $this->oneAction }}
    {{ $this->twoAction }}

    <x-filament-actions::modals />
</div>
// test 2
<div class="flex justify-end">
    {{ $this->oneAction }}
    {{ $this->twoAction }}

    <x-filament-actions::modals />
</div>
// test 3
<div class="flex justify-between">
    {{ $this->oneAction }}
    {{ $this->twoAction }}

    <x-filament-actions::modals />
</div>

ericmp33 avatar Jul 24 '24 18:07 ericmp33

Could you please do the same video for icon button actions, @ericmp33? Currently those have a negative margin to account for spacing, which this PR might break. Not sure though, hence I'm asking for the video :)

zepfietje avatar Jul 25 '24 09:07 zepfietje

I updated the tests & fixed the code. Here you have a table to know what functions I used for both actions in each test.

->icon('heroicon-s-pencil') ->iconButton()
TestX false false
TestXb true false
TestXc true true

*For each test, the 1st action is always disabled and the 2nd it's not.

Before:

https://github.com/user-attachments/assets/aeaca375-2afc-4ff0-8934-42e0f58694c6

After:

https://github.com/user-attachments/assets/77a8106f-fd40-4645-8e27-aafcd3911500

ericmp33 avatar Jul 25 '24 13:07 ericmp33

Think I'm going to push this to v4 since it does have some capability to be a breaking change with certain style customizations

danharrin avatar Jul 31 '24 09:07 danharrin