Hi,
Recently I have a problem with my live
, so I decided to create a minimal example to reproduce issue. However even after I did it I have no idea why my code have such behaviour …
I have started with phoenix_live_view.exs from mix-install-examples
repository. The only change is to replace a template and handle_*
callbacks with this code:
def render(assigns) do
~L"""
<textarea id="test1" phx-keydown="test"><%= @text %></textarea>
<textarea id="test2" phx-keydown="test"><%= @text %></textarea>
"""
end
def handle_event("test", %{"key" => key}, socket) do
{:noreply, assign(socket, :text, key <> "lixir")}
end
So what’s the issue? As in title the problem is with the assign, but only the element which fires the test
keydown event. When I focus the #test1
and type E
then in this textarea
the content stays E
and in #test2
it’s correctly changed to Elixir
.
However if I change template to:
def render(assigns) do
~L"""
<div contenteditable id="test1" phx-keydown="test"><%= @text %></div>
<div contenteditable id="test2" phx-keydown="test"><%= @text %></div>
"""
end
and add some basic styles to layout:
div {
height: 100px;
width: 100px;
}
#test1 {
background-color: cyan;
}
#test2 {
background-color: pink;
}
then both div
elements have Elixir
after pressing E
key in any of element regardless of which one is firing event.
Is it a known bug or am I doing something wrong?