eshans
Hi all - am pretty new to this whole ecosystem. Was tasked with trying to build an autocomplete search dropdown similar to this
Autocomplete component — Vuetify - it should be resusable across different parts of the site - it will basically entail two parts: a regular input for typing into, and a panel underneath it for rendering the options and selection behavior
Here’s my code. Having a tough time figuring out where to start but wanted to just do it with dummy data and not any server side datalists yet. Thanks in advance for any guidance if anyone can offer. Is this all feasible without JS?
is where is starts.
defmodule LevelWeb.UI.AutocompleteDropdown do
@moduledoc false
use LevelWeb, :live_component
@variants %{
default: %{
select_container: "px-[1rem] py-[0.5rem] border border-[#D0D5DD] rounded-full bg-white",
placeholder_text: "text-base font-normal",
icon: "fa-caret-down text-base"
},
primary: %{
select_container: "pl-[1.5rem] py-[0.625rem] pr-[1.25rem] border border-[#D0D5DD] rounded-lg bg-white",
placeholder_text: "text-sm font-medium",
icon: "fa-chevron-down text-[0.625rem]"
},
primary_rounded: %{
select_container: "pl-[1.5rem] py-[0.625rem] pr-[1.25rem] border border-[#D0D5DD] rounded-full bg-white",
placeholder_text: "text-sm font-medium",
icon: "fa-chevron-down text-[0.625rem]"
}
}
@dynamic_styles %{
select_container: "border-blue"
}
@impl Phoenix.LiveComponent
def mount(socket) do
socket =
socket
|> assign_new(:menu_open?, fn -> false end)
|> assign_new(:placeholder_text, fn -> "Choose Major(s)" end)
|> assign_new(:variant, fn -> :default end)
|> assign_new(:chip_variant, fn -> :primary end)
{:ok, socket}
end
@impl Phoenix.LiveComponent
def render(assigns) do
assigns =
assigns
|> assign_new(:target, fn -> assigns.id end)
|> assign_new(:key, fn -> nil end)
|> assign_new(:render_chips?, fn -> true end)
~H"""
<div class="autocomplete-parent">
<div class="relative">
<input id={"#{@id}-search-input"} class="relative w-full appearance-none border border-gray-detailBorder rounded-xl bg-transparent py-0.5 pr-1 text-sm placeholder:text-[#666] focus:outline-none lg:w-[36rem]" type="text" list="matches" placeholder="Search.." />
<datalist id="matches">
<option>test1</option>
<option>test2</option>
<option>test3</option>
</datalist>
</div>
</div>
"""
end
@impl Phoenix.LiveComponent
def handle_event("toggle_menu", _, socket) do
socket = assign(socket, :menu_open?, !socket.assigns.menu_open?)
{:noreply, socket}
end
@impl Phoenix.LiveComponent
def handle_event("close_menu", _, socket) do
socket = assign(socket, :menu_open?, false)
{:noreply, socket}
end
@spec is_selected?(map(), list(map())) :: boolean()
defp is_selected?(item, selected_items) do
Enum.find(selected_items, fn i -> i.value == item.value end) != nil
end
end
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Joep
You could check out: LiveSelect v1.7.5 — Documentation
ghenry
Have a read of and adapt Typeahead with LiveView and Tailwind · FullstackPhoenix
eshans
Thanks a lot!
eshans
appreciate it, thanks!