[Live Components] Use JS events as Live Listeners #3110
sblondeau
started this conversation in
RFC - Feature Ideas
Replies: 1 comment 1 reply
-
Hey! I'm having a tiny doubt... is that not possible already in stimulus directly with some |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When I use Live component, I have few limitations with certain JS event
to deals with it, we need
1/ to create a stimulus controller
2/ it is not possible to add 2 or more data-action / data-live-action-param
e.g,
Furthermore, I have no info related to the event. For key event, I would like to get the pressed key, for scroll event, the y position in the page, etc.
My solution would be to send the JS event data in a LiveListener, I made few test and I seems to work well.
In the live_controller.js, when the action() function is triggered, I get the JS event and its properties, and I emit a liveListener with name "DOM:"
action(event) {
In the PHP live component, I can do
or
#[LiveListener('DOM:scroll')]
public function domEventCl(#[LiveArg] $event)
{
$this->y = $event['scrollY'] ?? 0;
if($this->y > 200) {
$this->showBottom();
}
}
With this solution, I can
It's really a POC, but it works. What do you think about this ? @Kocal @smnandre ?
Beta Was this translation helpful? Give feedback.
All reactions