03 · Formulários — texto
PasswordInput
mostrar/ocultar · força da senha · size · variant · state
Campo de senha com o botão de olho que mostra e oculta o que foi digitado.
Mostrar e ocultar · força crescendo
.heex
<div class="grid grid-cols-2 gap-4"> <.password_input id="pw01-a" label="Senha" value="Bompreco#202" loop /> <.password_input id="pw01-b" label="Nova senha" value="Bompreco#2026" visible strength="strong" help="Use 12 ou mais caracteres" wrapper_class="[&_[data-part=password-meter-bar]]:animate-[lu-pw_5s_ease-in-out_infinite] [&_[data-part=password-meter-bar]:nth-child(2)]:animate-[lu-pw2_5s_ease-in-out_infinite] [&_[data-part=password-meter-bar]:nth-child(3)]:animate-[lu-pw3_5s_ease-in-out_infinite] [&_[data-part=password-meter-bar]:nth-child(4)]:animate-[lu-pw4_5s_ease-in-out_infinite]" /> </div>
size × variant
sm
md
lg
outlined
filled
.heex
<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) 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"> <.password_input id={"pw02-#{variant}-#{size}"} variant={variant} size={size} value="password1234" aria-label="Senha" class="[&_input]:field-sizing-content" /> </div> <% end %> </div>
força · state
.heex
<div class="grid grid-cols-4 gap-4"> <.password_input id="pw03-1" label="Fraca" value="abc123" visible strength="weak" help="Muito curta" /> <.password_input id="pw03-2" label="Média" value="abc123" visible strength="fair" help="Adicione símbolos" /> <.password_input id="pw03-3" label="Boa" value="abc123" visible strength="good" help="Quase lá" /> <.password_input id="pw03-4" label="Forte" value="abc123" visible strength="strong" help="Senha forte" /> </div>
erro e desabilitado
.heex
<div class="grid grid-cols-2 gap-4"> <.password_input id="pw04-1" label="Senha atual" value="password1234" state="error" help="Senha incorreta" /> <.password_input id="pw04-2" label="Senha" value="password1234" disabled /> </div>
Valores da API que completam a paridade
variant=plain
state=success
state=error
.heex
<div class="grid grid-cols-3 gap-3.5"> <div class="flex flex-col items-start gap-1.5"><.password_input id="pw05-1" variant="plain" value="password1234" aria-label="Senha" /><span class="font-mono text-[11px] text-muted">variant=plain</span></div> <div class="flex flex-col items-start gap-1.5"><.password_input id="pw05-2" state="success" value="password1234" aria-label="Senha" /><span class="font-mono text-[11px] text-muted">state=success</span></div> <div class="flex flex-col items-start gap-1.5"><.password_input id="pw05-3" state="error" value="password1234" aria-label="Senha" /><span class="font-mono text-[11px] text-muted">state=error</span></div> </div>
Uso
<.password_input field={@form[:password]} label="Senha" autocomplete="new-password" /> <.password_input field={@form[:password]} show_label="Mostrar a senha" hide_label="Ocultar a senha" size="lg" />
Regras
- O olho alterna entre pontos e texto; o rótulo acessível troca junto (
show_label/hide_label). - Senha nova: mostre a força em 4 segmentos abaixo do campo.
Referência da API
Todos os function components, atributos, valores e slots que este componente cobre.
A password field with the eye button that shows what was typed.
<.password_input name="password" placeholder="Enter password" />
<.password_input field={@form[:password]} label="Senha" autocomplete="new-password" />
It is an input/1 of type="password" (it takes every attr of input/1) with a lock at the
start and an eye at the end. The button flips the type between password and text, swaps
the icon and the accessible name with Phoenix.LiveView.JS, so it needs no hook.
<.password_input>
Renders the field and the eye.
| Attr | Type | Default | Values / notes |
|---|---|---|---|
id |
:string |
nil |
Defaults to the field id, then name; characters that break a CSS selector are replaced. |
show_label |
:string |
"Show the password" |
|
hide_label |
:string |
"Hide the password" |
|
class |
:any |
nil |
|
field |
{:struct, Phoenix.HTML.FormField} |
nil |
|
name |
:string |
nil |
|
value |
:any |
nil |
|
label |
:string |
nil |
|
help |
:string |
nil |
|
errors |
:list |
[] |
|
placeholder |
:string |
nil |
|
disabled |
:boolean |
false |
|
size |
:string |
"md" |
sm, md, lg |
variant |
:string |
"outlined" |
outlined, filled, plain |
state |
:string |
nil |
nil, `,success,error` |
visible |
:boolean |
false |
Starts with the text shown (the eye crossed out); the button hides it. |
loop |
:boolean |
false |
Demo animation (CSS only): the dots and the text of value swap by themselves. The field is type="text" and the dots are drawn over it. |
strength |
:string |
nil |
nil, weak, fair, good, strong - Draws the strength meter (1 to 4 bars) under the field; scoring the password is yours. |
autocomplete |
:string |
nil |
|
required |
:boolean |
nil |
|
minlength |
:integer |
nil |
|
maxlength |
:integer |
nil |
|
form |
:string |
nil |
Any other HTML/phx attribute goes to the root element, including label_hint, layout, wrapper_class, shape, align, readonly.
Slots:
<:below><:label_aside>