Compose Unstyled 2.0 is out! Check the official announcement blog ->

Anchored tooltips with configurable side, alignment, and panel styling.

Use tooltips for short, contextual explanations that appear near an anchor.

View on GitHub
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.dp
import com.composables.ui.components.Button
import com.composables.ui.components.ButtonStyle
import com.composables.ui.components.Text
import com.composables.ui.components.Tooltip
import com.composables.ui.components.TooltipAlignment
import com.composables.ui.components.TooltipPanel
import com.composables.ui.components.TooltipSide

@Composable
fun TooltipExample() {
    Tooltip(
        panel = {
            TooltipPanel {
                Text("Tooltip")
            }
        },
    ) {
        Button(onClick = {}, style = ButtonStyle.Outlined) {
            Text("Hover me")
        }
    }
}

Installation

implementation("com.composables:ui:0.1.0")

Examples

Side

View on GitHub
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.dp
import com.composables.ui.components.Button
import com.composables.ui.components.ButtonStyle
import com.composables.ui.components.Text
import com.composables.ui.components.Tooltip
import com.composables.ui.components.TooltipPanel
import com.composables.ui.components.TooltipSide

@Composable
fun TooltipSideExample() {
    Row(
        horizontalArrangement = Arrangement.spacedBy(12.dp),
    ) {
        TooltipButton(
            side = TooltipSide.Start,
            label = "Start",
            tooltipText = "Placed on the leading side",
        )
        TooltipButton(
            side = TooltipSide.Top,
            label = "Top",
            tooltipText = "Placed above the anchor",
        )
        TooltipButton(
            side = TooltipSide.Bottom,
            label = "Bottom",
            tooltipText = "Placed below the anchor",
        )
        TooltipButton(
            side = TooltipSide.End,
            label = "End",
            tooltipText = "Placed on the trailing side",
        )
    }
}

@Composable
private fun TooltipButton(
    label: String,
    tooltipText: String,
    side: TooltipSide,
) {
    Tooltip(
        side = side,
        panel = { TooltipPanel { Text(text = tooltipText) } },
    ) {
        Button(onClick = {}, style = ButtonStyle.Outlined) {
            Text(text = label)
        }
    }
}

Alignment

View on GitHub
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.dp
import com.composables.ui.components.Button
import com.composables.ui.components.ButtonStyle
import com.composables.ui.components.Text
import com.composables.ui.components.Tooltip
import com.composables.ui.components.TooltipAlignment
import com.composables.ui.components.TooltipPanel

@Composable
fun TooltipAlignmentExample() {
    Row(
        horizontalArrangement = Arrangement.spacedBy(12.dp),
    ) {
        TooltipButton(
            label = "Start",
            tooltipText = "Aligned to the start edge",
            alignment = TooltipAlignment.Start,
        )
        TooltipButton(
            label = "Center",
            tooltipText = "Aligned to the center",
            alignment = TooltipAlignment.Center,
        )
        TooltipButton(
            label = "End",
            tooltipText = "Aligned to the end edge",
            alignment = TooltipAlignment.End,
        )
    }
}

@Composable
private fun TooltipButton(
    label: String,
    tooltipText: String,
    alignment: TooltipAlignment,
) {
    Tooltip(
        alignment = alignment,
        panel = { TooltipPanel { Text(text = tooltipText) } },
    ) {
        Button(onClick = {}, style = ButtonStyle.Outlined) {
            Text(text = label)
        }
    }
}

Hover delay

View on GitHub
import androidx.compose.runtime.Composable
import com.composables.ui.components.Button
import com.composables.ui.components.ButtonStyle
import com.composables.ui.components.Text
import com.composables.ui.components.Tooltip
import com.composables.ui.components.TooltipPanel

@Composable
fun TooltipHoverDelayExample() {
    Tooltip(
        hoverDelayMillis = 600L,
        panel = {
            TooltipPanel {
                Text("Tooltip")
            }
        },
    ) {
        Button(onClick = {}, style = ButtonStyle.Outlined) {
            Text("Hover me")
        }
    }
}

Long press duration

View on GitHub
import androidx.compose.runtime.Composable
import com.composables.ui.components.Button
import com.composables.ui.components.ButtonStyle
import com.composables.ui.components.Text
import com.composables.ui.components.Tooltip
import com.composables.ui.components.TooltipPanel

@Composable
fun TooltipLongPressDurationExample() {
    Tooltip(
        longPressShowDurationMillis = 3_000L,
        panel = {
            TooltipPanel {
                Text("Tooltip")
            }
        },
    ) {
        Button(onClick = {}, style = ButtonStyle.Outlined) {
            Text("Long press me")
        }
    }
}

API Reference

Tooltip

An anchored tooltip with configurable placement and timing.

@Composable
fun Tooltip(
    enabled: Boolean = true,
    side: TooltipSide = TooltipSide.Top,
    alignment: TooltipAlignment = TooltipAlignment.Center,
    sideOffset: Dp = 8.dp,
    alignmentOffset: Dp = 0.dp,
    longPressShowDurationMillis: Long = 1500L,
    hoverDelayMillis: Long = 0L,
    panel: @Composable TooltipScope.() -> Unit,
    anchor: @Composable () -> Unit,
)
Parameter Type Description
enabled Boolean Whether the tooltip can be shown.
side TooltipSide Side of the anchor where the tooltip should appear.
alignment TooltipAlignment Alignment of the tooltip along the chosen side.
sideOffset Dp Distance between the tooltip and its anchor.
alignmentOffset Dp Offset applied along the anchor edge.
longPressShowDurationMillis Long Duration to keep the tooltip visible after a long press.
hoverDelayMillis Long Delay before showing the tooltip on hover.
panel @Composable TooltipScope.() -> Unit Composable tooltip panel content.
anchor @Composable () -> Unit Composable anchor that triggers the tooltip.

TooltipPanel

A styled tooltip surface drawn near the anchor.

@Composable
fun TooltipScope.TooltipPanel(
    modifier: Modifier = Modifier,
    shape: Shape = RoundedCornerShape(6.dp),
    backgroundColor: Color = Theme[colors][panelColor],
    contentColor: Color = Theme[colors][onPanelColor],
    outlineColor: Color = Theme[colors][borderColor],
    contentPadding: PaddingValues = PaddingValues(horizontal = 10.dp, vertical = 6.dp),
    enter: EnterTransition? = null,
    exit: ExitTransition? = null,
    content: @Composable () -> Unit,
)
Parameter Type Description
modifier Modifier Modifier applied to the component.
shape Shape Shape used for the tooltip panel.
backgroundColor Color Background color used for the tooltip panel.
contentColor Color Color used for tooltip content.
outlineColor Color
contentPadding PaddingValues Padding applied inside the tooltip panel.
enter EnterTransition? Transition used when the tooltip appears.
exit ExitTransition? Transition used when the tooltip disappears.
content @Composable () -> Unit Composable content displayed by the component.

TooltipSide

Side options for tooltip placement relative to its anchor.

@JvmInline
value class TooltipSide internal constructor(private val value: Int)
Value Description
Top Places the tooltip above its anchor.
Bottom Places the tooltip below its anchor.
Start Places the tooltip before its anchor in the layout direction.
End Places the tooltip after its anchor in the layout direction.

TooltipAlignment

Alignment options for tooltip placement along the anchor edge.

@JvmInline
value class TooltipAlignment internal constructor(private val value: Int)
Value Description
Start Aligns the tooltip to the start edge of the anchor.
Center Centers the tooltip against the anchor.
End Aligns the tooltip to the end edge of the anchor.