fix: keep search term on refresh and enter
This commit is contained in:
parent
85e1f370f6
commit
eb42b9fe0a
1 changed files with 5 additions and 3 deletions
|
|
@ -8,10 +8,10 @@ defmodule MvWeb.Components.SearchBarComponent do
|
|||
use MvWeb, :live_component
|
||||
|
||||
@impl true
|
||||
def update(_assigns, socket) do
|
||||
def update(%{query: query}, socket) do
|
||||
socket =
|
||||
socket
|
||||
|> assign_new(:query, fn -> "" end)
|
||||
|> assign_new(:query, fn -> query || "" end)
|
||||
|> assign_new(:placeholder, fn -> gettext("Search...") end)
|
||||
|
||||
{:ok, socket}
|
||||
|
|
@ -20,7 +20,7 @@ defmodule MvWeb.Components.SearchBarComponent do
|
|||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<form phx-change="search" phx-target={@myself} class="flex" role="search" aria-label="Search">
|
||||
<form phx-submit="search" phx-target={@myself} class="flex" role="search" aria-label="Search">
|
||||
<label class="input">
|
||||
<svg
|
||||
class="h-[1em] opacity-50"
|
||||
|
|
@ -44,6 +44,8 @@ defmodule MvWeb.Components.SearchBarComponent do
|
|||
placeholder={@placeholder}
|
||||
value={@query}
|
||||
name="query"
|
||||
phx-change="search"
|
||||
phx-target={@myself}
|
||||
phx-debounce="300"
|
||||
/>
|
||||
</label>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue