12 · Overlays

Tooltip

color (9) · placement (12) · trigger hover/click/focus/manual · follow_cursor · shortcut

A short hint on hover or focus.

Appears on pointer hover

.heex
<div class="flex flex-wrap items-center gap-2.5">
  <div :for={{id, c, p, text, kbd} <- [{"tt-demo-top", "dark", "top", "Exportar", "⌘E"}, {"tt-demo-bottom", "neutral", "bottom", "Notificações", nil}, {"tt-demo-right", "light", "right", "Copiar link", nil}]} class="flex h-[110px] flex-col items-center justify-center gap-2">
    <.tooltip id={id} color={c} placement={p}><:trigger><.button canvas appearance="default" icon="download" aria-label="Exportar" /></:trigger>{text}<kbd :if={kbd}>{kbd}</kbd></.tooltip>
  </div>
</div>

color (9)

neutral neutral
light light
dark dark
primary primary
secondary secondary
info info
success success
warning warning
error error
.heex
<div class="grid grid-cols-3 gap-1 sm:grid-cols-9">
  <div :for={c <- ~w(neutral light dark primary secondary info success warning error)} class="flex h-[110px] flex-col items-center justify-center gap-2">
    <.tooltip id={"tt-c-#{c}"} color={c} text={c} open><.button canvas appearance="default" icon="download" aria-label="Exportar" /></.tooltip>
    <span class="font-mono text-xs text-muted">{c}</span>
  </div>
</div>

placement (12) · trigger hover/click/focus/manual · follow_cursor

top-start Exportar
top Exportar
top-end Exportar
right-start Exportar
right Exportar
right-end Exportar
bottom-start Exportar
bottom Exportar
bottom-end Exportar
left-start Exportar
left Exportar
left-end Exportar
trigger=hover (passe o ponteiro)
trigger=click (clique)
trigger=focus (foque com Tab)
.heex
<div class="overflow-x-auto">
  <div class="grid min-w-[640px] grid-cols-3 gap-x-4 gap-y-4">
    <div :for={p <- ~w(top-start top top-end right-start right right-end bottom-start bottom bottom-end left-start left left-end)} class="relative flex h-[132px] items-center justify-center">
      <span class="absolute left-2 top-1.5 font-mono text-xs text-muted">{p}</span>
      <.tooltip id={"tt-p-#{p}"} color="dark" placement={p} text="Exportar" open><.button canvas appearance="default" icon="download" aria-label="Exportar" /></.tooltip>
    </div>
  </div>
</div>
<div class="mt-4 flex flex-wrap items-center gap-x-10 gap-y-3 pt-12 pb-2">
  <div :for={{t, label} <- [{"hover", "trigger=hover (passe o ponteiro)"}, {"click", "trigger=click (clique)"}, {"focus", "trigger=focus (foque com Tab)"}]} class="flex flex-col items-center gap-2">
    <.tooltip id={"tt-t-#{t}"} color="dark" placement="top" trigger={t} text="Exportar"><.button canvas appearance="default" icon="download" aria-label="Exportar" /></.tooltip>
    <span class="font-mono text-xs text-muted">{label}</span>
  </div>
</div>

API values that complete the parity

initial follow_cursor=initial
horizontal follow_cursor=horizontal
vertical follow_cursor=vertical
both follow_cursor=both
.heex
<div class="grid grid-cols-4 gap-3.5">
  <div :for={f <- ~w(initial horizontal vertical both)} class="flex flex-col items-start gap-1.5">
    <.tooltip_tip color="dark">{f}</.tooltip_tip>
    <span class="font-mono text-[11px] text-muted">follow_cursor={f}</span>
  </div>
</div>

Usage

<.tooltip text="Exportar (⌘E)"><.button canvas appearance="default" … /></.tooltip>

Rules

  • Up to ~8 words; never put an action inside.
  • 400ms delay to open, 0 to switch between neighbors.

API reference

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

A short hint around a trigger (<.tooltip>).

<.tooltip id="save-tip" text="Save the draft">
  <.button>Save</.button>
</.tooltip>

<.tooltip id="top-start" text="Top Start" color="success" placement="top-start">
  <.button variant="outline">Top Start</.button>
</.tooltip>

<.tooltip id="profile" trigger="click">
  <.button>Content</.button>
  <:content><div class="p-3">...</div></:content>
</.tooltip>

The trigger is the inner block (or, with a <:trigger> slot, the slot, and the inner block is the hint: <.tooltip id="t"><:trigger><.button>Save</.button></:trigger>Save the draft</.tooltip>); the hint floats next to it (placement, 12 values) in any color. The LedgerUI.Float hook (priv/static/ledger_ui/hooks/float.js) shows it on hover/focus, click or never (manual), after delay ms, optionally following the cursor, and flips it when there is no room. LedgerUI.open/close/toggle("id") show and hide it, open drives it from the server. on_open / on_close take an event name (payload %{"id" => id}, sent to target) or a %JS{}.

<.tooltip>

Attr Type Default Values / notes
id (required) :string
text :string nil
color :string "neutral" neutral, light, dark, primary, secondary, info, success, warning, error
placement :string "top" top, top-start, top-end, right, right-start, right-end, bottom, bottom-start, bottom-end, left, left-start, left-end
delay :integer 0
duration :integer 300
follow_cursor :string nil nil, `,both,horizontal,vertical,initial`
arrow :boolean true
interactive :boolean nil
open :boolean false
on_open :any nil
on_close :any nil
target :any nil
class :any nil
tip_class :any nil

Any other HTML/phx attribute goes to the root element, including trigger, content.

Slots:

  • <:content>
  • <:inner_block> (required)
  • <:trigger> - The element the hint hangs from; the inner block is then the hint.

<.tooltip_tip>

Only the bubble of a tooltip, in the page flow: no trigger, no hook, no floating. For previews and for hints you place yourself.

<.tooltip_tip arrow="bottom">Search <.kbd variant="dark">⌘K</.kbd></.tooltip_tip>
Attr Type Default Values / notes
color :string "neutral" neutral, light, dark, primary, secondary, info, success, warning, error
size :string "sm" sm, md - sm is the 12px hint of tooltip/1; md the larger 12.5px one (more padding, a deeper shadow).
arrow :string nil nil, top, bottom, left, right - The side the arrow is drawn on (it points away from the bubble); no arrow by default.
class :any nil

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

Slots:

  • <:inner_block> (required)