Skip to content

[LiveComponent] Use keyboard events #1065

Closed
@sblondeau

Description

@sblondeau

Hello,
I actually develop for fun a little RPG game, and I need to move a character in a map using keyboard arrows. My challenge is to make it work with live component of course :D

But I do not understand how to do it, as keypress events have to be attached to document, and not directly to the element, it do not find the data-action-name attached. Here the example :

in my component
<div id="map" {{attributes}} data-action="keydown.up@document->live#action" data-action-name="move(direction=N)">

The event is "working", but when I press arrow up, I get this error :

Error invoking action "keydown.up@document->live#action"
 TypeError: event.currentTarget.dataset is undefined

do you have any idea to make it work ? thanks for your help :-)
And if you could make it easier to use keyboard events, it could be very useful to make some cool interactions :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions