rappasoft/laravel-livewire-tables

[Bug]: `wire:click` on TR Elements Not Working in v3-master

nxgcx opened this issue · 13 comments

nxgcx commented

What happened?

It appears that wire:click assignment on TR elements does not work in V3.

How to reproduce the bug

The following no longer works in V3. In V2, you can observe that the wire:click attribute is assigned to the tr element in the DOM. In V3 though, the attribute is missing. Furthermore, it appears that any given attribute assignment done this way is also missing.

public function configure(): void
{
	$this->setTrAttributes(function($row, $index) {
		return ['wire:click' => "alert(\'Hello!\')"];
	}
}

Package Version

v3-master (4250511)

PHP Version

8.1.x

Laravel Version

10.24.0

Alpine Version

latest (Livewire 3.0.5)

Theme

Tailwind 3.x

Notes

No response

Error Message

No error message denoted

lrljoe commented

Can you try v3-develop for me, as there are quite a lot of fixes that I've yet to merge into Master

nxgcx commented

Can you try v3-develop for me, as there are quite a lot of fixes that I've yet to merge into Master

Just tried swapping (dev-v3-master 4250511 => dev-v3-develop 19b79b2), the issue is still present.

lrljoe commented

Okay, I can see that you cannot append a non-class attribute to the TR, so will look at the bug.

It is however worth noting thatt

return ['wire:click' => "alert(\'Hello!\')"];

Won't ever work, as when you add wire:click it will try to access the Livewire Function of that name. An x-on:click will allow for JS functions though:

            ->setTdAttributes(function(Column $column, $row, $columnIndex, $rowIndex) {
                return ['x-on:click' => "alert('Hello!')", 
                        'default' => false
                ];
            })

(that would make any column you click on return the "Hello!" alert box, which you may be able to use in the interim?

In terms of the TR and clickable, rather than bodging something, I'll probably need to review the TR clickable/click methods, and add in the relevant capabilities for using wireable/x:on-click events.

nxgcx commented

Okay, I can see that you cannot append a non-class attribute to the TR, so will look at the bug.

It is however worth noting thatt

return ['wire:click' => "alert(\'Hello!\')"];

Won't ever work, as when you add wire:click it will try to access the Livewire Function of that name. An x-on:click will allow for JS functions though:

            ->setTdAttributes(function(Column $column, $row, $columnIndex, $rowIndex) {
                return ['x-on:click' => "alert('Hello!')", 
                        'default' => false
                ];
            })

(that would make any column you click on return the "Hello!" alert box, which you may be able to use in the interim?

In terms of the TR and clickable, rather than bodging something, I'll probably need to review the TR clickable/click methods, and add in the relevant capabilities for using wireable/x:on-click events.

Sorry for the confusion, the alert call was just a placeholder from what we had in place to simplify the example. Thank you for checking in to this.

lrljoe commented

Not a problem, just working on a couple of other docs.

What's your ultimate use case for this (just so I can get my head around precisely what you're doing), and I'll make sure its part of the test suite for when I get this back in as a function.

nxgcx commented

Not a problem, just working on a couple of other docs.

What's your ultimate use case for this (just so I can get my head around precisely what you're doing), and I'll make sure its part of the test suite for when I get this back in as a function.

Clickable rows that pop up a modal (via openModal from the wire-elements/modal package). This is achieved by a call using $dispatch.

lrljoe commented

Ah awesome, that actually makes my life a tad easier as I'm very familiar with the WE Modals package.

Out of interest, why are you targeting the entire row, rather than a group of buttons?

nxgcx commented

Ah awesome, that actually makes my life a tad easier as I'm very familiar with the WE Modals package.

Out of interest, why are you targeting the entire row, rather than a group of buttons?

Perfect! There is a lot of content on the pages that this appears on and the table is fairly condensed, there is unfortunately no room for a button cell on each row.

lrljoe commented

Yep, can see why its not passing through properly.

Give me until tomorrow, as I'll need to write a few tests, but should be in v3-develop tomorrow PM.

nxgcx commented

Yep, can see why its not passing through properly.

Give me until tomorrow, as I'll need to write a few tests, but should be in v3-develop tomorrow PM.

No worries, thank you very much =)

lrljoe commented

Fix appears to work. so will look to merge it into develop and add tests over the weekend.

Few visual tests to do still before I can merge it in.

If you're on discord then can share the change to make in the interim, its one blade file that needs changing

lrljoe commented

Adding final tests now, merging into develop imminently

nxgcx commented

Adding final tests now, merging into develop imminently

I tried it and it works perfectly! Thank you so much! 🥰