Composable Component

TooltipBox

Material TooltipBox that wraps a composable with a tooltip.

TooltipBox

Common
@Composable
fun TooltipBox(
    positionProvider: PopupPositionProvider,
    tooltip: @Composable TooltipScope.() -> Unit,
    state: TooltipState,
    modifier: Modifier = Modifier,
    onDismissRequest: (() -> Unit)? = null,
    focusable: Boolean = false,
    enableUserInput: Boolean = true,
    hasAction: Boolean = false,
    content: @Composable () -> Unit,
)

Parameters

positionProvider PopupPositionProvider that will be used to place the tooltip relative to the anchor content.
tooltip the composable that will be used to populate the tooltip's content.
state handles the state of the tooltip's visibility.
modifier the Modifier to be applied to the TooltipBox.
onDismissRequest executes when the user clicks outside of the tooltip. By default, the tooltip will dismiss when it's being shown when a user clicks outside of the tooltip.
focusable Boolean that determines if the tooltip is focusable. When true, the tooltip will consume touch events while it's shown and will have accessibility focus move to the first element of the component. When false, the tooltip won't consume touch events while it's shown but assistive-tech users will need to swipe or drag to get to the first element of the component. For certain a11y cases, such as when the tooltip has an action and Talkback is on, focusable will be forced to true to allow for the correct a11y behavior.
enableUserInput Boolean which determines if this TooltipBox will handle long press and, mouse hover, and keyboard focus to trigger the tooltip through the state provided.
hasAction whether the associated tooltip contains an action.
content the composable that the tooltip will anchor to.