Skip to content

[0.81] Clamp Tooltip Position To Monitor - #16371

Open
Vineeth (vineethkuttan) wants to merge 3 commits into
0.81-stablefrom
tooltipfix
Open

[0.81] Clamp Tooltip Position To Monitor#16371
Vineeth (vineethkuttan) wants to merge 3 commits into
0.81-stablefrom
tooltipfix

Conversation

@vineethkuttan

@vineethkuttan Vineeth (vineethkuttan) commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a P0 bug reported by the Kindle team where React Native Windows tooltips rendered near screen edges (e.g. icons in the top-right corner) get cut off / clipped instead of staying fully visible.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Why

TooltipTracker::ShowTooltip  in  TooltipService.cpp  positioned the native tooltip popup window using only the cursor/anchor point ( pt.x - width/2 ,  pt.y - height - margin ), with no check against screen bounds. Tooltips anchored near a monitor edge could therefore render partially or fully outside the visible screen.

What

Added  ClampTooltipPositionToMonitor() :

• Resolves the monitor nearest the anchor point via  MonitorFromPoint  +  GetMonitorInfo(...).rcWork .
• Flips the tooltip below the anchor when there isn't enough room above (instead of clipping at the top).
• Clamps the final tooltip rect horizontally and vertically so it never extends past the monitor's work area.

 ShowTooltip  now uses this clamped position when creating the tooltip popup window, instead of the raw, unclamped offset.

This matches standard OS tooltip behavior (Win32/WinUI), where tooltips may extend beyond their owner window but are always kept fully within the visible screen.

Screenshots

Before :
image

After :
image

Testing

Tested in Playground

Changelog

Should this change be included in the release notes: yes

Clamp Tooltip Position according to the Monitor

Microsoft Reviewers: Open in CodeFlow

@vineethkuttan
Vineeth (vineethkuttan) marked this pull request as ready for review August 17, 2026 05:49
@vineethkuttan
Vineeth (vineethkuttan) requested a review from a team as a code owner August 17, 2026 05:49
Copilot AI balanced review requested due to automatic review settings August 17, 2026 05:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Clamps Fabric tooltip windows to the nearest monitor’s work area.

Changes:

  • Adds monitor-aware tooltip positioning and edge clamping.
  • Uses the clamped coordinates when creating tooltip windows.
  • Adds a patch changelog entry.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
TooltipService.cpp Adds monitor-aware tooltip placement.
Change JSON Records the patch release note.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread vnext/Microsoft.ReactNative/Fabric/Composition/TooltipService.cpp
Copilot AI review requested due to automatic review settings August 17, 2026 06:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (1)

vnext/Microsoft.ReactNative/Fabric/Composition/TooltipService.cpp:161

  • Capping these fields only shrinks the popup HWND; the IDWriteTextLayout was already created with the original constraints and WM_PAINT still renders that unchanged layout. Whenever either cap is hit, text outside the reduced client rect is therefore clipped, so an oversized tooltip is not actually fully visible. Resolve the monitor limits before creating the text layout (accounting for padding and scale), or recreate/update the layout with the capped content size and an explicit overflow/trimming policy before deriving the final window dimensions.
  tooltipWidth = std::min(tooltipWidth, static_cast<int>(bounds.right - bounds.left));
  tooltipHeight = std::min(tooltipHeight, static_cast<int>(bounds.bottom - bounds.top));

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (1)

vnext/Microsoft.ReactNative/Fabric/Composition/TooltipService.cpp:153

  • Capping only these window dimensions does not resize the already-created IDWriteTextLayout. If the measured tooltip exceeds the work area, CreateWindow gets the reduced size while RenderText still draws the original larger layout, so text is clipped (and any existing ellipsis can remain outside the client area). Please apply the monitor-derived bounds to the layout constraints before creating/measuring the text layout, then clamp using those resulting dimensions.
  // Cap the tooltip size to the work area so the position clamping below is guaranteed to keep
  // the whole tooltip on-screen, even for unusually long tooltip text.
  tooltipWidth = std::min(tooltipWidth, static_cast<int>(bounds.right - bounds.left));
  tooltipHeight = std::min(tooltipHeight, static_cast<int>(bounds.bottom - bounds.top));

@vineethkuttan Vineeth (vineethkuttan) changed the title Clamp Tooltip Position To Monitor [0.81] Clamp Tooltip Position To Monitor Aug 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

3 participants