Skip to main content

CamoTooltip

Concept​

1. Why​

A tooltip shows a short text label for an element that has no visible text, typically an icon button, when the user hovers (mouse), focuses (keyboard) or long-presses (touch). Desktop and web users expect them. They also settle an earlier open question: CamoIconButton gets a tooltip parameter on both platforms, built on this component.

2. Shape​

Material mapping preview: the M3 plain tooltip. inverseSurface container, inverseOnSurface text in bodySmall, shapes.extraSmall, height 24, 8 dp from the anchor. Rich tooltips are Later.

3. API​

Contract​

fun CamoTooltip(
text: String,
content: Slot, // the anchor
enabled: Boolean = true,
)

// shortcut on icon buttons (both platforms):
fun CamoIconButton(…, tooltip: String? = null) // null → no tooltip; commonly = contentDescription

State → renderer: TooltipState(text, visible). Slots: none. Core owns the triggers, timing and positioning.

Tokens used​

  • colors.inverseSurface, inverseOnSurface
  • typography.bodySmall, shapes.extraSmall
  • motion.durationShort (fade)

Component theme​

theme.components.tooltip: TooltipTheme?. Every field is nullable in the theme. The skin's defaults(theme) fills whatever isn't set (Material defaults shown). See Theme §3.10.

FieldTypeMaterial defaultWhat it's for
shapeShapeshapes.extraSmallcontainer corners
paddingPaddinghorizontal 8, vertical 4inner padding
offsetDp8gap from the anchor
textStyleCamoTextStylebodySmalltext
showDelay / hideDelayDuration500 ms / 1500 ms (touch)timing
maxWidthDp200text wraps beyond this
colorsTooltipColors(container, text)inverseSurface, inverseOnSurfaceevery color it uses

Accessibility​

  • The tooltip text becomes the anchor's description (not its name), so screen readers announce it without showing the popup.
  • It never takes focus. Esc hides it (WCAG 1.4.13: dismissible, hoverable, persistent).
  • The pointer can move onto the tooltip without it disappearing (hoverable).

4. Build steps​

  1. Triggers and timing (hover delay, focus, long-press), sharing the anchored popup with CamoMenu.
  2. CamoTooltip, TooltipRenderer, the DebugSkin renderer, and the tooltip parameter on CamoIconButton.
  3. Tests:
    • it shows after the hover delay and on keyboard focus;
    • long-press shows it on touch;
    • Esc hides it;
    • the description is exposed;
    • it flips below at the top edge.

Done when

  • Top-bar icon buttons show tooltips on desktop and web hover and on keyboard focus, and on long-press on phones.

5. Edge cases​

CaseDecided behavior
Tooltip on a disabled elementShown on hover (explains why it's disabled). No focus trigger, because disabled elements aren't focusable.
Tooltip text equal to the anchor's labelNot announced twice. Core skips the description when it equals the name.
Rich tooltips (title + actions)Later (CamoRichTooltip, a CamoPopover-like component).

Implementation​

1. Why​

A tooltip needs three triggers (hover, keyboard focus, long-press), timing, and a popup positioned above its anchor, without stealing clicks. Material 3's TooltipBox isn't used; core builds it on the same popup plumbing as CamoMenu, with a non-focusable popup.

2. Shape​

3. API​

@Composable
public fun CamoTooltip(text: String, modifier: Modifier = Modifier, enabled: Boolean = true, content: @Composable () -> Unit)

CamoIconButton(tooltip = …) wraps itself in CamoTooltip.

  • Hover: pointerInput with awaitPointerEventScope reading PointerEventType.Enter/Exit (desktop, web, Android with a mouse, iPad pointer).
  • Focus: onFocusChanged { if (it.isFocused && lastInputWasKeyboard) show() }, so tapping doesn't show it but Tab does.
  • Long press: awaitEachGesture { awaitFirstDown(requireUnconsumed = false); … } detects a long press without consuming events, so the anchor's click still works; release doesn't trigger the click after a long press (the anchor's clickable already cancels on long press).
  • Popup: PopupProperties(focusable = false, dismissOnClickOutside = false); positioned centered above the anchor with style.offset, below if there's no room.
  • Semantics: Compose has no tooltip property, so core does two things when text differs from the anchor's label: it labels the long-press action (semantics { onLongClick(label = text) { … } }), which TalkBack reads as a hint, and it marks the visible popup text as a polite live region, so it's announced once when shown. When text equals the label, it adds nothing (no double reading).

4. Build steps​

  1. The trigger modifier, timers, the popup; TooltipTheme / Style; the DebugSkin renderer.
  2. UI tests: hover shows after the delay and hides on exit; Tab shows, tapping doesn't; long press shows without firing the click; no duplicate announcement when text equals the label.

Done when

  • Icon-button tooltips work with mouse, keyboard and touch on all targets.

5. Edge cases​

CaseDecided behavior
Disabled anchorHover still shows it (explains why it's disabled); no focus trigger.
Anchor scrolls away while shownThe tooltip hides.