Text input with an inline × clear button.
Provides clearable_input/1 — a text input that renders a × button on the
right side when the current value is non-empty. Clicking the button fires a
server event (:on_clear) which the LiveView handles to reset the value.
Also provides form_clearable_input/1 for changeset-integrated fields with
label, description, and error messages.
When to use
Use clearable_input/1 when users need a quick way to empty a field —
filter inputs, tag inputs, search boxes, or any single-line field where
removing the current value is a frequent action.
Basic usage
<.clearable_input
name="filter"
value={@filter}
placeholder="Filter by name..."
on_clear="clear_filter"
phx-change="filter_changed"
phx-debounce="300"
/>Handling clear
def handle_event("clear_filter", _params, socket) do
{:noreply, assign(socket, filter: "")}
endForm-integrated
<.form_clearable_input
field={@form[:username]}
label="Username"
on_clear="clear_username"
/>
Summary
Functions
Renders a text input with an inline × clear button.
Renders a form-integrated clearable input with label and error messages.
Functions
Renders a text input with an inline × clear button.
The × button is rendered only when :value is non-empty AND :on_clear is
set. Clicking it fires the LiveView event named by :on_clear. The LiveView
is responsible for resetting the field value, which causes the button to
disappear on re-render.
Examples
<.clearable_input name="q" value={@q} on_clear="clear_q" phx-change="search" />
<.clearable_input name="email" value={@email} type="email" placeholder="you@example.com" />Attributes
id(:string) - HTML id for the<input>. Auto-generated if nil. Defaults tonil.name(:string) - HTML name attribute. Defaults tonil.value(:string) - Current input value. Defaults tonil.type(:string) - HTML input type (text, email, tel, url, search). Defaults to"text".placeholder(:string) - Placeholder text shown when empty. Defaults tonil.on_clear(:string) - LiveView event name fired when the × button is clicked. Defaults tonil.disabled(:boolean) - Disables the input and hides the clear button. Defaults tofalse.class(:string) - Additional CSS classes merged into the<input>element viacn/1. Defaults tonil.- Global attributes are accepted. HTML attributes forwarded to the
<input>element. Supports all globals plus:["phx-change", "phx-debounce", "phx-keydown", "autocomplete", "required", "readonly", "autofocus"].
Renders a form-integrated clearable input with label and error messages.
Examples
<.form_clearable_input field={@form[:username]} label="Username" on_clear="clear_username" />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.on_clear(:string) - LiveView event name for the × clear button. Defaults tonil.class(:string) - Additional CSS classes merged into the<input>element. Defaults tonil.- Global attributes are accepted. HTML attributes forwarded to
clearable_input/1. Supports all globals plus:["phx-change", "phx-debounce", "autocomplete", "placeholder", "disabled", "required", "readonly", "type"].