Hey folks! I’m the author of Lustre which is a frontend framework written in Gleam. Lustre has the ability to run components as native Custom Elements with support for all the good stuff like attributes, properties, custom events, form association, …
I’m currently working on a headless ui library and I’d like to document and encourage its use in Phoenix and LiveView apps, but I’m not LV expert and it’s a little unclear to me how one is supposed to handle events emitted by a custom element. I found a thread from last year that asks a similar question but it looks like the conversation fizzled out.
As an example, the following is a hypothetical menu that supports both keyboard and pointer interaction. When a menu item is selected (by any means) the menu will emit an event - "lustre-ui:select"
- with a payload containing the value of the item selected.
<lustre-ui-menu>
<lustre-ui-menu-item value="ignore">
Ignore
</lustre-ui-menu-item>
<lustre-ui-menu-item value="block" class="danger">
Block
</lustre-ui-menu-item>
<lustre-ui-menu-item value="report" class="danger">
Report user profile
</lustre-ui-menu-item>
</lustre-ui-menu>
In a typical client app, you would attach an event listener to the <lustre-ui-menu>
element and perform whatever associated action when an item was selected, but of course what we’d like to do is send a message to our LiveView process some how.
As I understand it, LiveView only supports a fixed and predetermined set of native events for things like phx-click
. What would be the recommended way to work with custom elements that emit non-standard events in LV?
Thanks y’all!