Corex.Tooltip
(Corex v0.1.0-beta.4)
View Source
Phoenix implementation of Zag.js Tooltip.
Examples
Basic
<.tooltip id="my-tooltip">
<:trigger>Hover me</:trigger>
<:content>Tooltip content</:content>
</.tooltip>Multiple triggers (Zag)
One tooltip content, several triggers. Each value must be a stable non-empty string and unique within the component.
<.tooltip id="shared-tip" show_arrow={false}>
<:trigger value="a">First anchor</:trigger>
<:trigger value="b">Second anchor</:trigger>
<:content>Same panel for both triggers</:content>
</.tooltip>For multi-trigger tooltips whose <:content> should follow the active trigger in LiveView, set on_trigger_value_change to a handle_event/3 name and update assigns used inside <:content> (see the e2e Tooltip · Pattern page).
Without arrow
<.tooltip id="my-tooltip" show_arrow={false}>
<:trigger>Hover me</:trigger>
<:content>No arrow</:content>
</.tooltip>API Control
Use an id on the component for API control.
Client-side
<button phx-click={Corex.Tooltip.set_open("my-tooltip", true)}>
Open tooltip
</button>Server-side
def handle_event("open_tooltip", _, socket) do
{:noreply, Corex.Tooltip.set_open(socket, "my-tooltip", true)}
endStyling
Target parts with data-scope="tooltip" and data-part:
[data-scope="tooltip"][data-part="trigger"] {}
[data-scope="tooltip"][data-part="positioner"] {}
[data-scope="tooltip"][data-part="content"] {}
[data-scope="tooltip"][data-part="arrow"] {}Trigger and content have data-state="open" or data-state="closed".
On the root element, optional modifier classes:
tooltip--{semantic}— surface and ink (for exampletooltip--accent,tooltip--brand)tooltip--size-{sm|md|lg|xl}— max width, padding, and arrow scaletooltip--text-{scale}— content font size only (for exampletooltip--text-sm,tooltip--text-xl)
Summary
Components
Attributes
id(:string) - The id of the tooltip, useful for API to identify the tooltip.disabled(:boolean) - Whether the tooltip is disabled. Defaults tofalse.dir(:string) - The direction of the tooltip. When nil, derived from document. Defaults tonil. Must be one ofnil,"ltr", or"rtl".orientation(:string) - Layout orientation for CSS. Defaults to"horizontal". Must be one of"horizontal", or"vertical".open_delay(:integer) - Delay in ms before opening. Default from Zag is 400. Defaults to0.close_delay(:integer) - Delay in ms before closing. Default from Zag is 150. Defaults to0.positioning(Corex.Positioning) - Positioning options for the floating content. Defaults to%Corex.Positioning{hide_when_detached: true, strategy: "fixed", placement: "bottom", gutter: 8, shift: 0, overflow_padding: 0, arrow_padding: 4, flip: true, slide: true, overlap: false, same_width: false, fit_viewport: true, offset: nil}.close_on_escape(:boolean) - Whether to close on Escape. Default true. Defaults totrue.close_on_click(:boolean) - Whether to close on click. Default true. Defaults totrue.close_on_pointer_down(:boolean) - Whether to close on pointer down on the trigger. Default false. Defaults tofalse.close_on_scroll(:boolean) - Whether to close on scroll. Default false. Defaults tofalse.interactive(:boolean) - Whether the tooltip content is interactive (stays open when hovering content). Defaults totrue.on_open_change(:string) - The server event name when the open state changes. Defaults tonil.on_open_change_client(:string) - The client event name when the open state changes. Defaults tonil.on_trigger_value_change(:string) - LiveView event when the active trigger value changes (multi-trigger). Params include id (tooltip root) and value (trigger value string). Defaults tonil.show_arrow(:boolean) - Whether to show an arrow pointing to the trigger. Defaults totrue.trigger_tag(:atom) - Use :span when the tooltip sits inside another button-like control (e.g. tree view row) to avoid nested <button> elements. Defaults to:button. Must be one of:button, or:span.- Global attributes are accepted.
Slots
trigger(required) - Trigger element content. Use :let={tooltip} for assigns such as disabled. With more than one <:trigger>, each must set value="…" (unique, stable across LiveView patches). Accepts attributes:class(:string)value(:string)
content(required) - Tooltip content. Use :let={tooltip} for assigns such as disabled. Accepts attributes:class(:string)