Search input component with icon, optional clear button, and shortcut badge.
Provides search_input/1 — a styled text input with a magnifier icon on the
left, an optional × clear button, and an optional keyboard shortcut badge
(e.g. ⌘K). Supports three visual variants: :default, :minimal, :ghost.
Also provides form_search_input/1 for form-integrated search with label,
description, and changeset error display.
Variants
:default— bordered input with background (standard form use):minimal— no border, muted fill, for search bars inside containers:ghost— fully transparent until focused, for toolbar search
Basic usage
<%!-- Standalone search bar --%>
<.search_input
name="q"
value={@query}
placeholder="Search products..."
phx-change="search"
phx-debounce="300"
/>
<%!-- With command palette shortcut hint --%>
<.search_input
name="q"
value={@query}
placeholder="Search..."
shortcut="⌘K"
/>
<%!-- With clear button and custom variant --%>
<.search_input
name="q"
value={@query}
placeholder="Filter..."
variant="minimal"
on_clear="clear_search"
/>Handling clear
When :on_clear is set, the × button fires a phx-click event. Handle it
server-side to reset the search value:
def handle_event("clear_search", _params, socket) do
{:noreply, assign(socket, query: "")}
end
Summary
Functions
Renders a form-integrated search input with label and error messages.
Renders a search input with a magnifier icon, optional × clear button, and optional keyboard shortcut badge.
Functions
Renders a form-integrated search input with label and error messages.
Wraps search_input/1 with a <label> (when :label is given) and error
<p> elements sourced from field.errors.
Examples
<.form_search_input field={@form[:query]} label="Search products" />Attributes
field(Phoenix.HTML.FormField) (required) - APhoenix.HTML.FormFieldstruct from@form[:field_name].label(:string) - Label text rendered above the input. Defaults tonil.description(:string) - Helper text rendered below the label. Defaults tonil.variant(:string) - Visual style. Defaults to"default". Must be one of"default","minimal", or"ghost".shortcut(:string) - Keyboard shortcut badge. Defaults tonil.on_clear(:string) - LiveView event name for the × clear button. Defaults tonil.class(:string) - Additional CSS classes for the wrapper. Defaults tonil.- Global attributes are accepted. HTML attributes forwarded to the inner
search_input/1. Supports all globals plus:["phx-change", "phx-debounce", "phx-keydown", "disabled", "placeholder", "autocomplete"].
Renders a search input with a magnifier icon, optional × clear button, and optional keyboard shortcut badge.
The layout is a relative wrapper containing:
- A left-aligned magnifier icon
- The styled
<input type="search"> - (optional) × clear button firing
:on_clear - (optional) shortcut
<kbd>badge on the right
Examples
<.search_input name="q" value={@q} phx-change="search" phx-debounce="300" />
<.search_input name="q" value={@q} shortcut="⌘K" placeholder="Jump to..." />
<.search_input name="q" value={@q} on_clear="clear_q" variant="minimal" />Attributes
id(:string) - HTML id for the<input>. Auto-generated if nil. Defaults tonil.name(:string) - HTML name attribute forwarded to<input>. Defaults to"search".value(:string) - Current input value. Defaults tonil.placeholder(:string) - Placeholder text shown when the input is empty. Defaults to"Search...".variant(:string) - Visual style —default,minimal, orghost. Defaults to"default". Must be one of"default","minimal", or"ghost".shortcut(:string) - Keyboard shortcut badge displayed inside the input (e.g."⌘K"). Defaults tonil.on_clear(:string) - LiveView event name fired when the × clear button is clicked. Defaults tonil.disabled(:boolean) - Disables the input and clear button. Defaults tofalse.class(:string) - Additional CSS classes merged into the outer wrapper. Defaults tonil.- Global attributes are accepted. HTML attributes forwarded to the
<input>element. Supports all globals plus:["phx-change", "phx-submit", "phx-keydown", "phx-debounce", "autofocus", "autocomplete"].