hoetmaaiers

hoetmaaiers

Liveview navigate a list using keyboard events

I am bulding the TailwindCSS combobox as a Phoenix Liveview LiveComponent (What’s with the capitals :thinking:).
When clicking inside the input element, the combobox opens and I can navigate the elements using ArrowUp/Down setting the select item in the LiveComponent’s state. However, the input element stays in focus and the active list item seems to be only artificial.

What I mean with artificial feeling is that when I hit enter, the enter event is taking place on the input element which remain in focus. Another thing which feels wrong is when an element is selected outside of the combobox popover the items is not inside focus and dissapears behind the overflow…

Am I taking a wrong route over here? Should I do this with or without Javascript?

Marked As Solved

JohnnyCurran

JohnnyCurran

LiveView will never overwrite an active input’s value even if the client value differs from the LiveView’s rendered value

This portion of the docs is worth a read:

LiveView will never overwrite the input’s current value, even if it deviates from the server’s rendered updates

If I were you, I would do all of the client navigation (up, down, etc.) in just JS. when they select an item or hit enter, then send it to the LiveView.

For one, you won’t have the js/liveview source of truth collision. The second is that those server round trips are nice and snappy on local development, but are slower and feel slow once they are deployed to production.

Also Liked

Eiji

Eiji

I guess you are as confused as I was with LiveView’s behaviour, see:

hoetmaaiers

hoetmaaiers

Ok, thank you for the responses. Somehow I felt like 50% of the combobox was already doone and the path with LIveview only felt pretty good. I do understand the snappyness of this kind of interface would suffer from a roundtrip to the server.

For full solution reference, I went the web-components route as described in this topic: Phoenix LiveView + HeadlessUI

Thanks to @fteschke and @superchris for the inspiration.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31194 112
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement