Skip to content

fix(tooltip): follow layout changes and point the arrow at the target - 21.2.x - #18047

Open
Hristo313 wants to merge 5 commits into
21.2.xfrom
hhristov/fix-tooltip-position-21.2.x
Open

Hristo313 wants to merge 5 commits into
21.2.xfrom
hhristov/fix-tooltip-position-21.2.x

Conversation

@Hristo313

@Hristo313 Hristo313 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #17879

Description

  • IgxTooltipDirective: while the tooltip is open, it follows changes of its own size and of the size and the position of its target. A new internal observeTooltipLayout() (tooltip-layout-observer.ts) watches the tooltip and the target with a ResizeObserver, and the target position with an IntersectionObserver whose root is shrunk to the target, so a move without a size change is caught too. Changes are batched to one update per frame.
    • When only the target moved, the push that kept the tooltip in the viewport is cleared and the tooltip is fitted into the viewport anew at the new place of its target. So it is neither left off its target away from a viewport edge, nor clipped at one.
    • The observers watch the border box, so a change of the padding or of the border is caught too. The target is watched again after it resizes, because a smaller target can move inside the rectangle that it had. A move that happens before the first observer entry is reported, as in a move that takes several frames.
    • When a size changed, the fixed width of the overlay content is cleared, the natural size is measured away from the viewport edges, and the tooltip is fitted into the viewport anew, as when it opens.
  • TooltipPositionStrategy:
    • When fitInViewport pushes the tooltip with a translateX/translateY, the arrow moves back by the same amount and stays inside the tooltip, clear of its rounded corners, so it keeps pointing at the target. A start aligned arrow, which has no position style, is moved from its edge offset, the same one as an end aligned arrow.
    • The arrow is positioned by the layout sizes (offsetWidth/offsetHeight) instead of getBoundingClientRect(), so a reposition while the scaleInCenter open animation runs no longer places it for the scaled-down tooltip.
    • After a push, a zero arrow offset is written as 0px. Before, it left the arrow at its default place, next to a target that is at the very start of the tooltip.
  • Without a push and outside the animation, the arrow positions are the same as before.

Motivation / Context

In the Tooltip Overview sample, switching the theme with the documentation's theme picker while the sticky tooltip is open left the tooltip about 50px below its target, with its text wrapped to 4 lines in the width fixed for the previous theme. Turning off the close button left the smaller tooltip about 13px off center. In narrow sample frames, the arrow pointed next to the target. See #17879.

This is the port of #17880 to 21.2.x. The code is the same as in the master pull request. The new tests are written for Jasmine instead of Vitest, and the changelog entry is under 21.2.28.

Type of Change (check all that apply):

  • Bug fix
  • Tests
  • Changelog
  • Documentation

Component(s) / Area(s) Affected:

Tooltip

How Has This Been Tested?

  • Unit tests
  • Manual testing

Unit tests:

  • Four new tests: the arrow points at the target when the tooltip is pushed into the viewport, the arrow is positioned by the layout size while the tooltip is scaled, the tooltip follows its target when the target moves, and the tooltip takes its new size when its content changes. Each fails without its fix.
  • "Nested tooltips > should show arrow for each tooltip" now checks that the arrow of the first tooltip, which is pushed into the viewport, points at its target. Before, it checked that the arrow stayed at the center of the pushed tooltip.
  • After the review: a new tooltip-layout-observer.spec.ts with 8 tests for the observer, and 4 more tests for the directive: a move after the target has shrunk, a move over several frames, a new viewport fit after a move, and a zero arrow offset. Each of the five review findings has a test that fails without its fix.
  • Tooltip specs 82/82, grid validation and query builder specs 170/170.
  • On this branch the tooltip specs pass, 81/81, and the grid validation and query builder specs pass, 127/127.

Manual testing, in the dev demos with the Tooltip Overview sample of igniteui-angular-samples, the four theme presets switched at runtime as the samples' theme service does, and the master TooltipPositionStrategy side by side for comparison:

  • Material → Fluent → Material → Bootstrap → Indigo with the tooltip open: the gap stays at about 6px, the text stays on 2 lines, and the tooltip and the arrow stay centered on the target (within 1px).
  • Close button off and on: the tooltip stays centered at 121px and 147px.
  • Target at the left and the right viewport edge: the arrow points at the target, for the centered, start and end placements.
  • A window resize during the open animation: the arrow stays centered.

Test Configuration:

  • Angular version: 21.1
  • Browser(s): Chrome 156
  • OS: Windows 11

Checklist:

  • All relevant labels have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes CHANGELOG.MD updates for newly added functionality

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings November 24, 2026 14:09
Port of the master change to 21.2.x.

The new tests are written for Jasmine.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

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.

🟡 Changes recommended

Unresolved tooltip positioning defects can leave tooltips offset or clipped after movement and resizing, and misalign arrows when viewport correction requires a zero offset.

4 open issues
What changed in this PR

Ports the tooltip layout and arrow-positioning fixes from #17880 to 21.2.x, addressing #17879 in Ignite UI for Angular.

Changes:

  • Adds layout observers to reposition open tooltips when their target moves or dimensions change.
  • Adjusts arrow positioning for viewport pushes and scaled opening animations.
  • Adds Jasmine regression tests, usage documentation, and a 21.2.28 changelog entry.
File Description
projects/​igniteui-angular/​directives/​src/​directives/​tooltip/​tooltip.directive.ts Manages layout observation, resizing, and repositioning.
projects/​igniteui-angular/​directives/​src/​directives/​tooltip/​tooltip.directive.spec.ts Adds layout and arrow regression tests; updates nested-arrow assertions.
projects/​igniteui-angular/​directives/​src/​directives/​tooltip/​tooltip.common.ts Compensates arrows for viewport pushes and uses unscaled layout sizes.
projects/​igniteui-angular/​directives/​src/​directives/​tooltip/​tooltip-layout-observer.ts Observes size and target-position changes with frame-batched updates.
projects/​igniteui-angular/​directives/​src/​directives/​tooltip/​README.md Documents layout tracking and arrow correction.
CHANGELOG.md Records the tooltip fixes under 21.2.28.

Review effort: Balanced

- watch the border box, so padding and border changes are reported

- watch the target again after it resizes

- report a move that happens before the first observer entry

- fit a moved tooltip into the viewport anew

- keep a zero arrow offset after a push

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@IMinchev64 IMinchev64 added 💥 status: in-test PRs currently being tested and removed ❌ status: awaiting-test PRs awaiting manual verification labels Nov 26, 2026
Hristo313 and others added 2 commits November 26, 2026 20:07
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@IMinchev64 IMinchev64 added ✅ status: verified Applies to PRs that have passed manual verification and removed 💥 status: in-test PRs currently being tested labels Nov 27, 2026
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tooltip version: 21.2.x ✅ status: verified Applies to PRs that have passed manual verification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants