rappasoft / laravel-livewire-tables

A dynamic table component for Laravel Livewire
https://rappasoft.com/docs/laravel-livewire-tables/v2/introduction
MIT License
1.75k stars 328 forks source link

[Bug]: The TH style is applied twice #1939

Open mLicorn opened 1 week ago

mLicorn commented 1 week ago

What happened?

When I modify the TH style via the $thAttributesCallback property, the style is also applied to the span in sort button.

How to reproduce the bug

Modify TH padding via the setThAttributes method:

public function configure(): void
{
       $this->setThAttributes(fn() => [
            'default' => false,
            'class'   => 'px-10 py-10'
        ]);
}

Package Version

3.4.20

PHP Version

None

Laravel Version

11.22.0

Alpine Version

3.14.1

Theme

Tailwind 3.x

Notes

The problem comes from the resources/views/components/table/th.blade.php view.

$customAttributes is used for both TH and SPAN in the button.

Error Message

No response

lrljoe commented 6 days ago

Good spot! I'll look at getting this fixed for the next release.

lrljoe commented 6 days ago

So I've looked, and the reason behind this is that otherwise the button attributes get applied as it's sortable.

I'll look at adding in the methods to separate this a bit more cleanly!

lrljoe commented 16 hours ago

So the fix for this will be in the next release, which adds in a "setLabelAttributes" for:

This helps to mitigate the issue where the "thAttributes" were being applied twice (once for the th, and once for the label itself).

The underlying reason for this is the clash between setThAttributes and setThSortButtonAttributes

Now there's a setLabelAttributes which applies to the label itself, Then the setThAttributes, and setThSortButtonAttributes apply to their respective elements only.

Expect the release by the end of the week, or feel free to test it out via the "development" branch