Type-ahead inputs: a combobox, and a free-form tags field.
combobox/1 is a text input with suggestions — the user may pick one or type something
the list does not contain. tags_input/1 collects an arbitrary number of short values as
removable chips.
<.combobox name="city" label="City" options={@cities} />
<.tags_input name="labels" label="Labels" value={["bug", "urgent"]} />Combobox or select_menu?
Use select_menu when the value must be one of the options — it is a listbox, and there is
no way to submit anything else. Use combobox when the list is a convenience rather than a
constraint, and free text is legitimate.
Both support search; the difference is whether typing produces a value of its own.
Summary
Forms
Renders a text input with a filtered suggestion list.
Accessibility
Implements the ARIA combobox pattern: the input owns the listbox, tracks the highlighted
option with aria-activedescendant, and keeps focus in the input throughout — which is
what makes typing and arrowing work together. Up/Down move, Enter accepts, Escape closes.
Attributes
id(:string) - Defaults tonil.name(:string) (required)value(:string) - Defaults tonil.options(:list) -{label, value}tuples, or bare strings. Defaults to[].label(:string) - Defaults tonil.placeholder(:string) - Defaults to"Search…".hint(:string) - Defaults tonil.error(:string) - Defaults tonil.disabled(:boolean) - Defaults tofalse.required(:boolean) - Defaults tofalse.allow_custom(:boolean) - Allows a value that is not in the list. Set false to make the list authoritative. Defaults totrue.empty_message(:string) - Defaults to"No matches found.".class(:string) - Defaults tonil.container_class(:string) - Defaults tonil.- Global attributes are accepted.
Renders a free-form tags field.
Enter or the separator commits a tag; Backspace on an empty input removes the last one.
How the value reaches the server
Tags are user-created, so unlike select_menu there is no fixed set of inputs to
enable and disable. They are submitted as one value joined by separator:
String.split(params["labels"], ",", trim: true)The chip list is Alpine-rendered and therefore wrapped in phx-update="ignore", so
LiveView does not tear it out on the next patch. That means the server cannot change the
tags once rendered — drive it from the server with select_menu multiple instead if you
need that.
Attributes
id(:string) - Defaults tonil.name(:string) (required)value(:list) - The tags already present. Defaults to[].label(:string) - Defaults tonil.placeholder(:string) - Defaults to"Add a tag…".hint(:string) - Defaults tonil.error(:string) - Defaults tonil.disabled(:boolean) - Defaults tofalse.max(:integer) - Most tags allowed.nilmeans no limit. Defaults tonil.separator(:string) - Joins the tags in the submitted value, and also commits a tag when typed. Split on the same character server-side.Defaults to
",".class(:string) - Defaults tonil.container_class(:string) - Defaults tonil.Global attributes are accepted.