Input
variant outlined · filled · plain × size sm · md · lg × shape rounded · pill · align · state · layout inline · label_hint · ícone, prefixo e sufixo · tipos
Campo de texto de uma linha. Mesmos eixos da API: variant, size, shape, align, state, layout, label, label_hint, help, errors, prefixo/sufixo e ícone.
Foco e digitação
<div class="grid grid-cols-2 gap-4"> <.input label="Razão social" icon="user" value="Mercadinho Bom Preço Ltda" class="animate-[lu-focusloop_6s_ease-in-out_infinite] [&_input]:animate-[lu-typeloop_6s_steps(25)_infinite]" /> <.input label="CNPJ" icon="building" value="12.345.678/0001-0" errors={["CNPJ incompleto"]} class="animate-[lu-shake_6s_ease-in-out_infinite]" wrapper_class="[&_[data-part=error]]:animate-[lu-helperr_6s_ease-in-out_infinite]" /> </div>
variant × size
<div class="grid grid-cols-[90px_repeat(3,minmax(0,1fr))] items-center gap-x-3 gap-y-2.5"> <span></span> <span class="text-center font-mono text-xs text-muted">sm</span> <span class="text-center font-mono text-xs text-muted">md</span> <span class="text-center font-mono text-xs text-muted">lg</span> <%= for variant <- ~w(outlined filled plain) do %> <span class="font-mono text-xs text-muted">{variant}</span> <div :for={size <- ~w(sm md lg)} class="flex min-w-0 justify-center"> <.input variant={variant} size={size} icon="search" value="Mercadinho" aria-label="Busca" class="[&_input]:field-sizing-content" /> </div> <% end %> </div>
shape · align · ícones · prefixo/sufixo
<div class="grid grid-cols-3 gap-4"> <.input label='shape="rounded" (padrão)' icon="search" placeholder="Buscar pedidos" /> <.input label='shape="pill"' shape="pill" icon="search" placeholder="Buscar pedidos" /> <.input label='align="right" com prefixo' align="right" value="1.284,90" prefix="R$" /> <.input label="sufixo" align="right" value="12,5" suffix="%" /> <.input label="ícone à direita + atalho" icon="search" placeholder="Buscar…"><:trailing><span class="kbd">⌘K</span></:trailing></.input> <.input label="url com prefixo" value="signetum" prefix="https://" suffix=".com.br" /> </div>
state · help · errors · required · label_hint · disabled
<div class="grid grid-cols-2 gap-4"> <.input label="E-mail" icon="mail" type="email" value="ana@bompreco.com.br" state="success" help="E-mail verificado" /> <.input label="CNPJ" required value="12.345.678/0001" state="error" help="CNPJ incompleto: faltam 3 dígitos" /> <.input label="Apelido" label_hint="opcional" placeholder="Como aparece nas notas" help="Aparece no cabeçalho do DANFE" /> <.input label="Código interno" value="PED-2491" disabled help="Gerado automaticamente" /> </div>
layout="inline"
<div class="flex flex-col gap-2.5"> <.input label="Nome fantasia" layout="inline" value="Bom Preço" /> <.input label="Inscrição estadual" layout="inline" placeholder="Isento" /> </div>
type
<div class="grid grid-cols-4 gap-4"> <.input label="email" type="email" icon="mail" placeholder="nome@empresa.com" /> <.input label="search" type="search" icon="search" placeholder="Buscar…" /> <.input label="tel" type="tel" icon="phone" value="(75) 98123-4567" /> <.input label="url" type="url" icon="link" placeholder="https://" /> <.input label="date" type="date" icon="calendar" value="2026-11-19" /> <.input label="time" type="time" icon="clock" value="14:30" /> <.input label="number" type="number" value="42" /> <.input label="color" type="color" value="#1f9282" /> </div>
Valores da API que completam a paridade
"123.456.789-09"mask_submit=formatted"12345678909"mask_submit=raw<div class="flex flex-col gap-4"> <div class="grid grid-cols-3 gap-3.5"> <div class="flex flex-col items-start gap-1.5"><.input type="password" icon="lock" value="12345678" aria-label="password" /><span class="font-mono text-[11px] text-muted">type=password</span></div> <div class="flex flex-col items-start gap-1.5"><.input type="datetime-local" icon="calendar" value="2026-11-19T14:30" aria-label="datetime-local" /><span class="font-mono text-[11px] text-muted">type=datetime-local</span></div> <div class="flex flex-col items-start gap-1.5"><.input type="month" icon="calendar" value="2026-11" aria-label="month" /><span class="font-mono text-[11px] text-muted">type=month</span></div> <div class="flex flex-col items-start gap-1.5"><.input type="week" icon="calendar" value="2026-W47" aria-label="week" /><span class="font-mono text-[11px] text-muted">type=week</span></div> <div class="flex flex-col items-start gap-1.5"><.input type="file" icon="attach" aria-label="file" /><span class="font-mono text-[11px] text-muted">type=file</span></div> <div class="flex flex-col items-start gap-1.5"><.input placeholder="(não renderiza)" aria-label="hidden" /><span class="font-mono text-[11px] text-muted">type=hidden</span></div> </div> <div class="grid grid-cols-4 gap-3.5"> <div class="flex flex-col items-start gap-1.5"><.input value="Texto à esquerda" aria-label="align" /><span class="font-mono text-[11px] text-muted">align=left</span></div> <div class="flex flex-col items-start gap-1.5"><.input value="ok" state="success" aria-label="ok" /><span class="font-mono text-[11px] text-muted">state=success</span></div> <div class="flex flex-col items-start gap-1.5"><.input value="erro" state="error" aria-label="erro" /><span class="font-mono text-[11px] text-muted">state=error</span></div> <div class="flex flex-col items-start gap-1.5"><.input label="Rótulo em cima" value="valor" /><span class="font-mono text-[11px] text-muted">layout=stacked</span></div> </div> <div class="grid grid-cols-3 gap-3.5"> <div class="flex flex-col items-start gap-1.5"><.input id="in07-cpf" mask="cpf_cnpj" value="123.456.789-09" aria-label="cpf" /><span class="font-mono text-[11px] text-muted">mask=cpf_cnpj</span></div> <div class="flex flex-col items-start gap-1.5"><.input id="in07-cc" mask="credit_card" value="4111 1111 1111 1111" aria-label="cartão" /><span class="font-mono text-[11px] text-muted">mask=credit_card</span></div> <div class="flex flex-col items-start gap-1.5"><.input id="in07-num" mask="numeral" value="1.284.903,50" aria-label="valor" /><span class="font-mono text-[11px] text-muted">mask=numeral</span></div> <div class="flex flex-col items-start gap-1.5"><.input id="in07-blk" mask="blocks" mask_options={%{blocks: [3, 4, 2], delimiter: "-", uppercase: true}} value="ABC-1234-XY" aria-label="blocos" /><span class="font-mono text-[11px] text-muted">mask=blocks</span></div> <div class="flex flex-col items-start gap-1.5"><code class="inline-flex h-[30px] items-center gap-2 rounded-[8px] bg-sunken px-2.5 font-mono text-[13px]">"123.456.789-09"</code><span class="font-mono text-[11px] text-muted">mask_submit=formatted</span></div> <div class="flex flex-col items-start gap-1.5"><code class="inline-flex h-[30px] items-center gap-2 rounded-[8px] bg-sunken px-2.5 font-mono text-[13px]">"12345678909"</code><span class="font-mono text-[11px] text-muted">mask_submit=raw</span></div> </div> </div>
Uso
<.input field={@form[:name]} label="Nome" /> <.input field={@form[:total]} align="right" label="Total"><:prefix>R$</:prefix></.input> <.input field={@form[:email]} type="email" variant="filled" size="lg" state="success" help="E-mail verificado" /> <.input field={@form[:q]} shape="pill" layout="inline" label="Buscar" label_hint="opcional" />
Regras
- Padrão:
outlined,md(38px),rounded(raio 10). Pílula só quando pedido. plainpara campos dentro de um bloco já emoldurado;filledem barras e filtros.align="right"para valores; o prefixoR$fica fora do valor.- Foco: borda teal + anel de 3px. Erro: borda vermelha, a linha de ajuda vira a mensagem.
Referência da API
Todos os function components, atributos, valores e slots que este componente cobre.
Single-line text field styled only with Tailwind utilities: outlined, filled or plain,
rounded or pill, three sizes, icon, prefix and suffix, states, masks.
<.input field={@form[:name]} label="Nome" />
<.input field={@form[:total]} align="right" label="Total" prefix="R$" suffix="BRL" />
<.input field={@form[:email]} type="email" variant="filled" size="lg" state="success" help="E-mail verificado" />
<.input field={@form[:q]} shape="pill" layout="inline" label="Buscar" label_hint="opcional" />
field={@form[:name]} fills id, name, value and errors. With errors the help line shows
the messages and the box turns red.
Masks
mask formats what is typed (hook LedgerUI.InputMask, which needs a stable id; it comes
from field):
<.input name="doc" mask="cpf_cnpj" label="CPF ou CNPJ" mask_submit="raw" />
<.input name="amount" mask="numeral" mask_options={%{thousands: "lakh"}} />
<.input name="code" mask="blocks" mask_options={%{blocks: [3, 2, 3], delimiter: "-", uppercase: true}} />
| mask | options |
|---|---|
blocks |
blocks, delimiter, delimiters, prefix, uppercase, lowercase, numeric |
credit_card |
delimiter |
date |
pattern (~w(d m Y)), delimiter |
time |
pattern (~w(h m s)), delimiter |
phone |
blocks, delimiter |
cpf_cnpj |
none |
numeral |
thousands, decimals, delimiter, decimal_mark, positive, prefix |
The input submits the masked text; mask_submit="raw" submits the unmasked value through a
hidden input that carries the field's name.
Slots
prefix and suffix are text addons (R$, %, .com.br) separated by a divider. The slots
:leading and :trailing hold a control inside the box (a button, a kbd, a clear icon).
:label_aside goes at the right of the caption and :below between the box and the help line.
Shortcut
shortcut draws a kbd at the end of the field and focuses the field when the key is pressed
anywhere on the page (the search of a list):
<.input type="search" name="q" placeholder="Buscar" shortcut="/" />
The value is a combination as in hotkey/1 ("/", "Mod+k"); modifiers must match exactly, so
"/" does not fire with Ctrl, Meta or Alt. The press is ignored while the focus is in another
input, select, textarea or contenteditable element, and Esc inside the field takes the
focus out. The field gets aria-keyshortcuts and the kbd is aria-hidden. With several
fields with shortcut on one page, only the first visible one (in document order) answers.
The hook (LedgerUI.SearchShortcut) sits on the box, so it does not clash with mask's hook;
it needs an id (it comes from field, or is derived from name). Without shortcut the
markup is unchanged.
Inside an input_group use variant="plain": the group draws the shared border.
<.input>
Renders a text-like <input>, with its caption, help and errors when given.
| Attr | Type | Default | Values / notes |
|---|---|---|---|
field |
{:struct, Phoenix.HTML.FormField} |
nil |
A form field: fills id/name/value/errors. |
id |
:string |
nil |
|
name |
:string |
nil |
|
value |
:any |
nil |
|
type |
:string |
"text" |
text, email, password, number, search, tel, url, date, time, datetime-local, month, week, color, file, hidden |
variant |
:string |
"outlined" |
outlined, filled, plain |
size |
:string |
"md" |
lg, md, sm |
shape |
:string |
"rounded" |
rounded, pill |
align |
:string |
"left" |
left, right |
state |
:string |
nil |
nil, `,success,error` |
label |
:string |
nil |
|
label_class |
:any |
nil |
|
hint |
:string |
nil |
Text at the right of the label (alias: label_hint). |
label_hint |
:string |
nil |
|
optional |
:boolean |
false |
Adds "(opcional)" to the label. |
required |
:boolean |
false |
|
layout |
:string |
"stacked" |
stacked, inline |
help |
:string |
nil |
|
errors |
:list |
[] |
|
disabled |
:boolean |
false |
|
options |
:list |
[] |
Suggestions, rendered as the input's <datalist>. |
icon |
:string |
nil |
Icon name at the left of the text. |
prefix |
:string |
nil |
Text addon before the input (R$). |
suffix |
:string |
nil |
Text addon after the input (BRL). |
mask |
:string |
nil |
nil, `,blocks,credit_card,date,time,phone,numeral,cpf_cnpj` |
mask_options |
:map |
%{} |
|
mask_submit |
:string |
"formatted" |
formatted, raw |
clear_on_submit |
:boolean |
false |
|
shortcut |
:string |
nil |
A key that focuses the field ("/"); draws a kbd at the end. See "Shortcut". |
wrapper_class |
:any |
nil |
Classes of the field wrapper (caption, box, help). |
class |
:any |
nil |
Classes of the box. |
Any other HTML/phx attribute goes to the root element, including accept, autocomplete, autofocus, form, list, max, maxlength, min, minlength, multiple, pattern, placeholder, readonly, step, inputmode, size.
Slots:
<:below><:label_aside><:leading>- A control at the start of the box, after the icon.<:trailing>- A control at the end of the box (a button, akbd).