Textarea
variant outlined · filled · plain × size · counter (normal, aviso, excedido, mínimo) · autogrow · resizable · tokens · header/footer · state
Texto de várias linhas com contador ao vivo, crescimento automático e variáveis de modelo destacadas.
Crescendo e contando
<div class="grid grid-cols-2 gap-4"> <.textarea id="ta01-a" label="Observações" autogrow help="autogrow até 6 linhas" value={"Entregar após as 14h.\nPortão lateral, falar com Rita.\nLevar maquininha."} frame_class="border-accent-500! shadow-[0_0_0_3px_var(--lu-focus)]" class="overflow-hidden animate-[lu-tagrow_6s_ease-in-out_infinite]" /> <.textarea id="ta01-b" label="Mensagem ao cliente" counter loop maxlength={200} help="Até 200 caracteres" value="Seu pedido saiu para entrega e chega hoje entre 14h e 16h." frame_class="border-accent-500! shadow-[0_0_0_3px_var(--lu-focus)]" /> </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"> <.textarea variant={variant} size={size} placeholder="Escreva uma observação…" aria-label="Observação" class="field-sizing-content" /> </div> <% end %> </div>
counter
<%!-- the canvas shows a short text with a 184/200 and a 214/200 counter: the demo pads the value with zero-width spaces (U+200B) so the real counter reaches those counts without visible filler --%> <div class="grid grid-cols-4 gap-4"> <.textarea id="ta03-1" label="normal" counter maxlength={200} value="Cliente pediu nota com CPF." /> <.textarea id="ta03-2" label="aviso (≥ 90%)" counter maxlength={200} value={String.pad_trailing("Texto longo quase no limite…", 184, "")} /> <.textarea id="ta03-3" label="excedido" counter maxlength={200} state="error" value={String.pad_trailing("Texto que passou do limite…", 214, "")} /> <.textarea id="ta03-4" label="mínimo" counter min_length={20} value="Curto" help="Explique o motivo" /> </div>
tokens · header/footer · resizable
<div phx-no-curly-interpolation class="grid grid-cols-2 gap-4"> <.textarea id="ta04-tokens" label="Modelo de mensagem" tokens value="Olá, {{cliente}}! Sua nota {{numero}} foi autorizada. O boleto vence em {{vencimento}}."> <:header><span class="text-xs text-muted">Variáveis: </span><.chip label="{{cliente}}" /><.chip label="{{numero}}" /></:header> <:footer><.icon name="bold" size="sm" /><.icon name="italic" size="sm" /><.icon name="link" size="sm" /><span class="ml-auto text-xs text-muted tabular-nums">96 / 300</span></:footer> </.textarea> <.textarea id="ta04-rz" label="Redimensionável" resizable value="Arraste o canto para aumentar." /> </div>
state
<div class="grid grid-cols-2 gap-4"> <.textarea id="ta05-ok" label="Motivo" state="success" value="Cancelado a pedido do cliente." help="Motivo registrado" /> <.textarea id="ta05-err" label="Motivo" state="error" placeholder="Obrigatório" help="Informe o motivo do cancelamento" /> </div>
Valores da API que completam a paridade
<div class="grid grid-cols-4 gap-3.5"> <div class="flex flex-col items-start gap-1.5"><div class="flex items-baseline gap-2.5"><span class="ml-auto text-xs text-muted tabular-nums">26 / 200</span></div><span class="font-mono text-[11px] text-muted">counter_align=end</span></div> <div class="flex flex-col items-start gap-1.5"><div class="flex items-baseline gap-2.5"><span class="text-xs text-muted tabular-nums">26 / 200</span></div><span class="font-mono text-[11px] text-muted">counter_align=start</span></div> <div class="flex flex-col items-start gap-1.5"><.textarea id="ta06-ok" state="success" value="Ok" aria-label="Sucesso" /><span class="font-mono text-[11px] text-muted">state=success</span></div> <div class="flex flex-col items-start gap-1.5"><.textarea id="ta06-err" state="error" value="Erro" aria-label="Erro" /><span class="font-mono text-[11px] text-muted">state=error</span></div> </div>
Uso
<.textarea field={@form[:obs]} rows={4} maxlength={200} counter /> <.textarea field={@form[:msg]} tokens autogrow max_rows={8} /> <.textarea field={@form[:bio]} min_length={20} counter counter_format="%{count} de %{max}" />
Regras
- Contador: avisa (âmbar) a partir de 90% do limite e fica vermelho ao passar.
autogrowcresce com o texto atémax_rows.tokensdesenha{{nome}}em mono, apagado.
Referência da API
Todos os function components, atributos, valores e slots que este componente cobre.
Multi-line text field: outlined, filled or plain, fixed or resizable, with a live
character counter, autogrow, {{token}} highlighting and optional header/footer bars.
<.textarea field={@form[:bio]} label="Bio" variant="filled" resizable />
<.textarea name="note" maxlength={200} counter autogrow max_rows={8} />
<.textarea name="why" counter min_length={20} counter_format="%{count} de %{max}" />
<.textarea name="msg" tokens value="A fatura {{fatura.numero}} esta atrasada." />
<.textarea name="post" rows={5}>
<:header><span class="text-xs text-muted">Variaveis</span></:header>
<:footer><span>toolbar</span></:footer>
</.textarea>
With counter, maxlength is a soft limit: the counter warns from 90% and turns red past it,
and the browser does not refuse the characters (validate on the server).
The counter (counter), autogrow and tokens run in the LedgerUI.Textarea hook, which
needs a stable id (it comes from field, or name). The counter updates while typing, without
the server. A plain textarea needs no hook.
<.textarea>
Renders a <textarea> inside its frame, with its caption, help and errors.
| Attr | Type | Default | Values / notes |
|---|---|---|---|
field |
{:struct, Phoenix.HTML.FormField} |
nil |
|
id |
:string |
nil |
|
name |
:string |
nil |
|
value |
:any |
nil |
|
rows |
:integer |
nil |
Lines shown. Without it the field is the design's 84px (min-height); more lines make it taller. |
variant |
:string |
"outlined" |
outlined, filled, plain |
size |
:string |
nil |
nil, sm, md, lg |
resizable |
:boolean |
false |
|
counter |
:boolean |
false |
|
counter_format |
:string |
"%{count} / %{max}" |
|
counter_align |
:string |
"end" |
end, start |
min_length |
:integer |
nil |
|
autogrow |
:boolean |
false |
|
loop |
:boolean |
false |
Demo animation (CSS only, needs counter): the counter counts up (12, 168, 196, warning colours). value is not counted. |
max_rows |
:integer |
nil |
|
tokens |
:boolean |
false |
|
state |
:string |
nil |
nil, `,success,error` |
label |
:string |
nil |
|
label_class |
:any |
nil |
|
label_hint |
:string |
nil |
|
help |
:string |
nil |
|
errors |
:list |
[] |
|
disabled |
:boolean |
false |
|
wrapper_class |
:any |
nil |
|
frame_class |
:any |
nil |
|
class |
:any |
nil |
Any other HTML/phx attribute goes to the root element, including autocomplete, autofocus, cols, form, maxlength, minlength, placeholder, readonly, required, wrap.
Slots:
<:footer>- Content below the text, laid out as a row (ml-autosends an item to the end).<:header>- Content above the text, laid out as a row.