Skip to content

Fix tooltip hiding condition in TooltipArea#2798

Open
m-sasha wants to merge 1 commit intojb-mainfrom
m-sasha/fix-tooltip-hiding
Open

Fix tooltip hiding condition in TooltipArea#2798
m-sasha wants to merge 1 commit intojb-mainfrom
m-sasha/fix-tooltip-hiding

Conversation

@m-sasha
Copy link

@m-sasha m-sasha commented Feb 26, 2026

TooltipArea currently attempts to detect the pointer exiting "into the tooltip" (to avoid hiding the tooltip in this case) by checking whether the location of the pointer is inside the TooltipArea. This is wrong, however, because:

  1. There could be a real exit event (not into the tooltip) while the pointer is still inside the bounds of the tooltip area. For example, when exiting through the left edge, the exit event could be at x=0.
  2. The pointer could exit into another, overlapping, element. Here too, the tooltip should be hidden even though the pointer is inside the bounds of the tooltip area.

Fixes https://youtrack.jetbrains.com/issue/CMP-8739

Testing

Tested manually and added several unit tests.

@OptIn(ExperimentalComposeUiApi::class)
fun main() = singleWindowApplication {
    Box(Modifier.size(200.dp)) {
        BoxWithTooltip(text = "Red", color = Color.Red, Modifier.size(150.dp))
        BoxWithTooltip(text = "Blue", color = Color.Blue, Modifier.align(Alignment.BottomEnd).size(150.dp))
    }
}

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun BoxWithTooltip(
    text: String,
    color: Color,
    modifier: Modifier = Modifier,
    content: @Composable BoxScope.() -> Unit = {}
) {
    TooltipArea(
        tooltip = { Text(text, Modifier.background(Color.White).border(1.dp, Color.Black).padding(8.dp)) },
        modifier = modifier
    ) {
        Box(modifier = Modifier.fillMaxSize().background(color)) {
            content()
        }
    }
}

Release Notes

Fixes - Desktop

  • Fixed the condition for hiding the tooltip in a TooltipArea on a pointer-exit event while the pointer is still inside the area.

@m-sasha m-sasha requested a review from igordmn February 26, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant