Skip to content

Capture global keypress event to dismiss modal #288

@mwx23

Description

@mwx23

Lately I've been using tailwindcss and daisyui for my UI css. There's some nice css behaviours those libs have to handle visibility etc that seems to get swallowed by lona. This issue isn't about that (I'll post a minimal example later), as a work-around I'd just like to capture key events. Specifically if a modal is displayed and esc is pressed, toggle close the modal.

My general question is it possible to capture a keypress event and have it sent to the backend?

I've tried handle_input_event_root on a LonaView and handle_input_event on a Widget but that doesn't seem to work unless a TextInput is involved and focused.

I can write a frontend widget to do this (I think) but is there a more lona way to achieve this?

If I were to generalise the issue even more, is there a way to subscribe to frontend DOM events from the backend? This might be out of scope, but I saw in other issues you talking about v2 so I'm hopeful :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is neededquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions