LineOne's tabs: underlined (line), on a gray track (boxed), rounded (pill) and plain text (text), laid out
horizontally or vertically, with or without icons.
<.tabs id="profile-tabs" selected="home">
<:tab name="home">Home</:tab>
<:tab name="profile">Profile</:tab>
<:panel name="home">…</:panel>
<:panel name="profile">…</:panel>
</.tabs>
<.tabs id="boxed" variant="boxed">
<:tab name="home"><svg class="size-4.5">…</svg><span>Home</span></:tab>
<:panel name="home">…</:panel>
</.tabs>The selected tab comes from selected and switching happens in the browser (click, ←/→ or ↑/↓,
Home and End) without a round trip. A choice made in the browser survives patches; when the
server changes selected, the server wins.
on_change tells the server what was chosen:
<.tabs id="server-tabs" selected={@tab} on_change="select_tab">…</.tabs>
<.tabs id="period" variant="boxed" size="sm"><:tab name="month">Last month</:tab></.tabs>
<.tabs id="range" variant="text"><:tab name="week">Last 7 days</:tab><:tab name="all">All time</:tab></.tabs>
def handle_event("select_tab", %{"id" => "server-tabs", "value" => tab}, socket),
do: {:noreply, assign(socket, tab: tab)}Every selection also dispatches a bubbling linea:change DOM event with
detail: %{id: id, value: name, tab: name}.
Summary
Functions
Renders a tab list and its panels. Each :tab is matched to the :panel with the same name.
Functions
Renders a tab list and its panels. Each :tab is matched to the :panel with the same name.
<.tabs id="settings" selected={@tab} variant="boxed" on_change="tab_changed">
<:tab name="general">General</:tab>
<:tab name="billing" disabled>Billing</:tab>
<:panel name="general">…</:panel>
<:panel name="billing">…</:panel>
</.tabs>Events: with on_change="tab_changed" the hook pushes "tab_changed" with
%{"id" => "settings", "value" => "general", "tab" => "general"} (to target or the closest LiveComponent)
after the browser switched; with on_change={%JS{}} the commands run on the tabs element.
Either way a bubbling linea:change DOM event carries detail: %{id, value, tab}; tab repeats value.
Attributes
id(:string) (required) - Needed by the hook and for the tab/panel ids.selected(:string) - Thenameof the selected tab; the first one when not given. Defaults tonil.variant(:string) -lineunderlines the selected tab,boxedlifts it off a gray track,pillfills a rounded tab,textis plain text that only changes color (no border or background; spacing comes fromlist_class,space-x-4by default). Defaults to"line". Must be one of"line","boxed","pill", or"text".size(:string) - Forboxed:mdispx-3 py-1.5,smis LineOne's compactpx-3 py-1 text-xs-plus,xsispx-2.5 py-0.5 text-xs. Defaults to"md". Must be one of"xs","sm", or"md".color(:string) - The fill of the selectedpilltab and the text color of the selectedtexttab. Defaults to"primary". Must be one of"primary", or"neutral".orientation(:string) - Defaults to"horizontal". Must be one of"horizontal", or"vertical".bordered(:boolean) - Forline: draws the gray rule the tabs sit on. Defaults tofalse.overlap(:boolean) - For aborderedline: the selected tab's line covers the gray rule instead of sitting on it. Defaults tofalse.grow(:boolean) - The tabs share the whole width of the list. Defaults tofalse.transition(:string) - The way a panel comes in: sliding from the right (left) or from below (up). Defaults to"left". Must be one of"left","up", or"none".on_change(:any) - Run when a tab is chosen in the browser. An event name is pushed with%{"id" => id, "value" => name, "tab" => name}; a%JS{}is executed on the tabs element.Defaults to
nil.target(:any) - Thephx-targetofon_change. Defaults tonil.list_class(:any) - Extra classes for the tab list. Defaults tonil.panels_class(:any) - Extra classes for the wrapper of the panels. Defaults tonil.class(:any) - Defaults tonil.Global attributes are accepted.
Slots
tab(required) - A tab button; its content is the label, icons included. Accepts attributes:name(:string) (required) - Matches the:panelit shows and is theon_changevalue.disabled(:boolean) - Skipped by clicks and the arrow keys.class(:any)
panel- The content shown while the tab with the samenameis selected. Accepts attributes:name(:string) (required) - Thenameof its tab.class(:any)