Skip to content

Fix tooltip hiding condition in TooltipArea#2798

Merged
Alexander Maryanovsky (m-sasha) merged 1 commit into
jb-mainfrom
m-sasha/fix-tooltip-hiding
Mar 2, 2026
Merged

Fix tooltip hiding condition in TooltipArea#2798
Alexander Maryanovsky (m-sasha) merged 1 commit into
jb-mainfrom
m-sasha/fix-tooltip-hiding

Conversation

@m-sasha

@m-sasha Alexander Maryanovsky (m-sasha) commented Feb 26, 2026

Copy link
Copy Markdown

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

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

@m-sasha Alexander Maryanovsky (m-sasha) merged commit c7dc9fc into jb-main Mar 2, 2026
17 checks passed
@m-sasha Alexander Maryanovsky (m-sasha) deleted the m-sasha/fix-tooltip-hiding branch March 2, 2026 11:41
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.

2 participants