Text input
Collects a single line of text, such as a name, an email, a URL, or a search query.
Types
type
sets the prefix icon and the suffix.
input_type
sets the HTML input type.
⌘K
⌘K
<.text_input id="text-input-type-basic" name="project" placeholder="ios-app" />
<.text_input
id="text-input-type-email"
type="email"
input_type="email"
name="email"
/>
<.text_input
id="text-input-type-search"
type="search"
name="search"
placeholder="Search projects"
/>
<.text_input id="text-input-type-password" type="password" input_type="password" name="password" />
<.text_input
id="text-input-type-card-number"
type="card_number"
name="card_number"
placeholder="0000 0000 0000 0000"
/>
Label and hint
label
and
sublabel
sit above the input and
hint
below it.
*
(Shown in your project URLs)
Username may only contain alphanumeric characters
<.text_input
id="text-input-label-hint"
name="username"
label="Username"
sublabel="(Shown in your project URLs)"
placeholder="tuist"
hint="Username may only contain alphanumeric characters"
required
show_required
/>
Error
error
takes the place of the hint.
Enter a valid email address
<.text_input
id="text-input-error"
type="email"
input_type="email"
name="email"
label="Email"
value="marek@tuist"
error="Enter a valid email address"
/>
Prefix and suffix
Custom content before and after the value, or a tooltip with
suffix_hint
.
Create a token with tuist project tokens create.
<.text_input
id="text-input-prefix"
name="endpoint_url"
label="Endpoint URL"
placeholder="https://hooks.example.com/tuist"
>
<:prefix><.world /></:prefix>
</.text_input>
<.text_input id="text-input-suffix" name="branch" label="Default branch" value="main">
<:suffix><.git_branch /></:suffix>
</.text_input>
<.text_input
id="text-input-suffix-hint"
name="token"
label="Project token"
placeholder="tuist_"
suffix_hint="Create a token with tuist project tokens create."
/>
Disabled
<.text_input
id="text-input-disabled"
type="email"
input_type="email"
name="email"
label="Email"
disabled
/>
With a form field
With
field
, the name, value, and error come from the form.
<.form
:let={f}
for={to_form(%{"handle" => "tuist"}, errors: [handle: {"has already been taken", []}])}
>
<.text_input id="text-input-field" field={f[:handle]} label="Organization handle" />
</.form>
Guidelines
-
typesets the prefix icon and the suffix, whileinput_typesets the HTML input type, which defaults totext. Pairtype="password"withinput_type="password"so the value is masked, andtype="email"withinput_type="email"for the email keyboard and validation. -
Inside a form, pass
field. The input then takes its id, name, value, and first error from the form field. -
errorreplaces the hint and outlines the input. Passshow_error_message={false}to keep the outline without the message. -
requiredsets the HTML attribute. Addshow_requiredto also show the asterisk next to the label. -
The
searchtype shows a ⌘K shortcut but does not bind it. Passshow_suffix={false}when nothing on the page listens for it. -
For other HTML input types, such as
dateornumber, keeptypeasbasicand setinput_type. Number inputs also takemin,max, andstep.
API reference
<.text_input>
| Attribute | Type | Default | Description |
|---|---|---|---|
|
disabled
|
boolean
|
false
|
Whether the input is disabled.
|
|
error
|
string
|
–
|
Errors to be rendered below the input. Takes precedence over
hint
.
|
|
field
|
Phoenix.HTML.FormField
|
–
|
A Phoenix form field
|
|
hint
|
string
|
nil
|
Hint text to be rendered below the input.
|
|
hint_variant
|
string
|
"default"
|
Hint text variant.
|
|
id
|
string
|
–
|
|
|
input_type
|
string
|
"text"
|
HTML input type when type is
basic
.
|
|
label
|
string
|
nil
|
Label to be rendered in the input.
|
|
label_tooltip
|
string
|
nil
|
Help text shown in a tooltip from an icon after the label.
|
|
max
|
any
|
nil
|
Maximum value for number inputs.
|
|
min
|
any
|
nil
|
Minimum value for number inputs.
|
|
name
|
string
|
–
|
The name of the input
|
|
placeholder
|
string
|
nil
|
Placeholder text to be rendered in the input.
|
|
required
|
boolean
|
false
|
Whether the input is required.
|
|
show_error_message
|
boolean
|
true
|
Whether to show the error message below the input.
|
|
show_prefix
|
boolean
|
true
|
Whether to show the prefix.
|
|
show_required
|
boolean
|
false
|
Whether the required indicator is shown.
|
|
show_suffix
|
boolean
|
true
|
Whether to show the suffix.
|
|
step
|
any
|
nil
|
Step value for number inputs.
|
|
sublabel
|
string
|
nil
|
Sublabel to be rendered in the input.
|
|
suffix_hint
|
string
|
nil
|
Hint text to show as tooltip at the end of the input. Takes precedence over the suffix set by
type
.
|
|
type
|
string
|
"basic"
|
Type of the input
"basic""email""card_number""search""password"
|
|
value
|
string
|
–
|
The value of the input
|
Also accepts global attributes, including autocompletereadonly.
| Slot | Description |
|---|---|
|
:prefix
|
Prefix to be rendered in the input. Only shown when type is
basic
.
|
|
:suffix
|
Suffix to be rendered in the input. Takes precedence over
suffix_hint
.
|