11 · Navegação

Tabs

variant line · boxed · pill · text · segmented · nav × size xs/sm/md · color primary/neutral · vertical · transition left/up

Abas para alternar seções de uma mesma página.

O indicador desliza e o painel entra

transition="left"
transition="up"
.heex
<div class="grid grid-cols-2 gap-4">
  <div class="flex flex-col gap-1">
    <.tabs id="tabs1-left" variant="line" transition="left" selected="a" loop>
      <:tab name="a" class="w-[110px] justify-center">Visão geral</:tab>
      <:tab name="b" class="w-[110px] justify-center">Faturas</:tab>
      <:tab name="c" class="w-[110px] justify-center">Uso</:tab>
      <:panel name="a" class="flex flex-col gap-2"><.skeleton animation="none" class="h-2.5 w-[40%]" /><.skeleton animation="none" class="h-2.5 w-[80%]" /><.skeleton animation="none" class="h-2.5 w-[65%]" /></:panel>
      <:panel name="b" class="flex flex-col gap-2"><.skeleton animation="none" class="h-2.5 w-[55%]" /><.skeleton animation="none" class="h-2.5 w-[30%]" /><.skeleton animation="none" class="h-2.5 w-[90%]" /><.skeleton animation="none" class="h-2.5 w-[60%]" /></:panel>
      <:panel name="c" class="flex flex-col gap-2"><.skeleton animation="none" class="h-2.5 w-[70%]" /><.skeleton animation="none" class="h-2.5 w-[45%]" /></:panel>
    </.tabs>
    <span class="font-mono text-xs text-muted">transition="left"</span>
  </div>
  <div class="flex flex-col gap-1">
    <.tabs id="tabs1-up" variant="line" transition="up" selected="a" loop>
      <:tab name="a" class="w-[110px] justify-center">Visão geral</:tab>
      <:tab name="b" class="w-[110px] justify-center">Faturas</:tab>
      <:tab name="c" class="w-[110px] justify-center">Uso</:tab>
      <:panel name="a" class="flex flex-col gap-2"><.skeleton animation="none" class="h-2.5 w-[40%]" /><.skeleton animation="none" class="h-2.5 w-[80%]" /><.skeleton animation="none" class="h-2.5 w-[65%]" /></:panel>
      <:panel name="b" class="flex flex-col gap-2"><.skeleton animation="none" class="h-2.5 w-[55%]" /><.skeleton animation="none" class="h-2.5 w-[30%]" /><.skeleton animation="none" class="h-2.5 w-[90%]" /><.skeleton animation="none" class="h-2.5 w-[60%]" /></:panel>
      <:panel name="c" class="flex flex-col gap-2"><.skeleton animation="none" class="h-2.5 w-[70%]" /><.skeleton animation="none" class="h-2.5 w-[45%]" /></:panel>
    </.tabs>
    <span class="font-mono text-xs text-muted">transition="up"</span>
  </div>
</div>

variant × size

xssmmdline
boxed
pill
text
segmented
nav
.heex
<div class="grid grid-cols-[90px_repeat(3,_minmax(0,1fr))] gap-y-[10px] gap-x-[12px] items-center"><span></span><span class="text-xs text-muted font-mono text-center">xs</span><span class="text-xs text-muted font-mono text-center">sm</span><span class="text-xs text-muted font-mono text-center">md</span><span class="text-xs text-muted font-mono">line</span><div class="flex justify-center min-w-0"><.tabs id="t2-line-xs" variant="line" size="xs" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><div class="flex justify-center min-w-0"><.tabs id="t2-line-sm" variant="line" size="sm" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><div class="flex justify-center min-w-0"><.tabs id="t2-line-md" variant="line" size="md" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><span class="text-xs text-muted font-mono">boxed</span><div class="flex justify-center min-w-0"><.tabs id="t2-boxed-xs" variant="boxed" size="xs" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><div class="flex justify-center min-w-0"><.tabs id="t2-boxed-sm" variant="boxed" size="sm" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><div class="flex justify-center min-w-0"><.tabs id="t2-boxed-md" variant="boxed" size="md" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><span class="text-xs text-muted font-mono">pill</span><div class="flex justify-center min-w-0"><.tabs id="t2-pill-xs" variant="pill" size="xs" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><div class="flex justify-center min-w-0"><.tabs id="t2-pill-sm" variant="pill" size="sm" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><div class="flex justify-center min-w-0"><.tabs id="t2-pill-md" variant="pill" size="md" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><span class="text-xs text-muted font-mono">text</span><div class="flex justify-center min-w-0"><.tabs id="t2-text-xs" variant="text" size="xs" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><div class="flex justify-center min-w-0"><.tabs id="t2-text-sm" variant="text" size="sm" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><div class="flex justify-center min-w-0"><.tabs id="t2-text-md" variant="text" size="md" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><span class="text-xs text-muted font-mono">segmented</span><div class="flex justify-center min-w-0"><.tabs id="t2-segmented-xs" variant="segmented" size="xs" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><div class="flex justify-center min-w-0"><.tabs id="t2-segmented-sm" variant="segmented" size="sm" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><div class="flex justify-center min-w-0"><.tabs id="t2-segmented-md" variant="segmented" size="md" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><span class="text-xs text-muted font-mono">nav</span><div class="flex justify-center min-w-0"><.tabs id="t2-nav-xs" variant="nav" size="xs" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><div class="flex justify-center min-w-0"><.tabs id="t2-nav-sm" variant="nav" size="sm" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div><div class="flex justify-center min-w-0"><.tabs id="t2-nav-md" variant="nav" size="md" selected="all"><:tab name="all">Todas</:tab><:tab name="open">Abertas</:tab><:tab name="paid">Pagas</:tab></.tabs></div></div>

color (pill e text) · orientation="vertical"

.heex
<div class="flex flex-wrap items-center gap-2.5"><div class="flex flex-col gap-[10px]"><.tabs id="t3-pp" variant="pill" color="primary" selected="ov"><:tab name="ov">Visão geral</:tab><:tab name="inv">Faturas</:tab><:tab name="use">Uso</:tab></.tabs><.tabs id="t3-pn" variant="pill" color="neutral" selected="ov"><:tab name="ov">Visão geral</:tab><:tab name="inv">Faturas</:tab><:tab name="use">Uso</:tab></.tabs><.tabs id="t3-tp" variant="text" color="primary" selected="ov"><:tab name="ov">Visão geral</:tab><:tab name="inv">Faturas</:tab><:tab name="use">Uso</:tab></.tabs><.tabs id="t3-tn" variant="text" color="neutral" selected="ov"><:tab name="ov">Visão geral</:tab><:tab name="inv">Faturas</:tab><:tab name="use">Uso</:tab></.tabs></div><.tabs id="t3-vl" variant="line" orientation="vertical" selected="bill"><:tab name="gen">Geral</:tab><:tab name="bill">Cobrança</:tab><:tab name="team">Equipe</:tab><:tab name="int">Integrações</:tab></.tabs><.tabs id="t3-vn" variant="nav" orientation="vertical" selected="gen"><:tab name="gen">Geral</:tab><:tab name="bill">Cobrança</:tab><:tab name="team">Equipe</:tab></.tabs></div>

Valores da API que completam a paridade

orientation=horizontal
sem animação ao trocar transition=none
.heex
<div class="grid grid-cols-3 gap-[14px]"><div class="flex flex-col items-start gap-1.5"><.tabs id="t5" role={nil} selected="g"><:tab name="g" role={nil}>Geral</:tab><:tab name="f" role={nil}>Fiscal</:tab></.tabs><span class="font-mono text-[11px] text-muted">orientation=horizontal</span></div><div class="flex flex-col items-start gap-1.5"><.chip label="sem animação ao trocar" /><span class="font-mono text-[11px] text-muted">transition=none</span></div></div>

Uso

<.tabs id="account"><:tab id="overview" active>Visão geral</:tab>…</.tabs>

Regras

  • Abas trocam conteúdo da página; para filtrar dados use Segmented.
  • Indicador de 2px em ink, não em teal.
  • transition define como o painel entra: left (desliza da direita) ou up (sobe).

Referência da API

Todos os function components, atributos, valores e slots que este componente cobre.

Tabs: line, boxed, pill, text, segmented and nav, plus the classic underline tabs with count badges, horizontal or vertical. Styled only with Tailwind utilities; the selected tab carries data-state="on" (and aria-selected) and the utilities read it (data-[state=on]:text-ink...).

<.tabs id="profile" selected="home" on_change="select_tab">
  <:tab name="home">Home</:tab>
  <:tab name="profile" count={4}>Profile</:tab>
  <:panel name="home">...</:panel>
  <:panel name="profile">...</:panel>
</.tabs>

Switching happens in the browser through the hook LedgerUI.Tabs (priv/static/ledger_ui/hooks/tabs.js): click, ←/→ (↑/↓ when vertical), Home and End, no round trip. A choice made in the browser survives patches; when the server changes selected the server wins. on_change (an event name or a %JS{}) is pushed with %{"id" => id, "value" => name, "tab" => name}, and every selection dispatches a bubbling ledger:change event with detail: {id, value, tab}.

Tabs with patch, navigate or href are links (aria-current="page" when selected).

Notes on the markup

The server renders the ARIA: role="tablist" (+ aria-orientation when vertical), tab buttons with role="tab", aria-selected, the roving tabindex and aria-controls (when there is a panel); the hook only updates aria-selected/tabindex/data-state as the selection changes. color (primary, the default look, or neutral) tints the pill and text variants. Panels are role="tabpanel" boxes that the hook shows/hides; there is no sliding transition, transition is exposed as data-transition for apps that style it (and loop runs the canvas demo where the panels come in from the left or from below by themselves). bordered, overlap and grow are kept for compatibility and have no visual effect.

Every part carries data-part: tabs, tabs-list, tab, tab-count, tabs-panels, tabs-panel.

Additive tab attrs: role (pass nil to drop it) and count_tone (acc, neg...).

<.tabs>

Attr Type Default Values / notes
id (required) :string
selected :string nil
variant :string "line" line, boxed, pill, text, segmented, nav, classic
size :string "md" xs, sm, md
color :string nil nil, primary, neutral
orientation :string "horizontal" horizontal, vertical
bordered :boolean false
overlap :boolean false
grow :boolean false
transition :string "left" left, up, none
loop :boolean false The canvas demo (variant="line", up to 3 tabs): the indicator slides under the tabs, the tab text follows it and the panels come in (transition left or up) every 6s, by themselves.
loop_widths :list ~c"nnn" loop: the widths in px of the tabs (set them yourself, e.g. class="w-[110px]") to place the indicator; the gap is the 22px of the line list.
on_change :any nil
soon_label :string "Em breve"
target :any nil
list_class :any nil
panels_class :any nil
class :any nil

Any other HTML/phx attribute goes to the root element.

Slots:

  • <:panel> - attrs: name (required), class
  • <:tab> (required) - attrs: name, active, disabled, count, overdue, count_tone, patch, navigate, href, replace, soon, role, aria-selected, title, id, class, phx-click, phx-target, phx-value-id, phx-value-name