Skip to content

fix(trigger): keep popup position when trigger element is hidden - #3667

Open
Mowmowj wants to merge 1 commit into
arco-design:mainfrom
Mowmowj:fix/trigger-hidden-anchor-reposition
Open

fix(trigger): keep popup position when trigger element is hidden#3667
Mowmowj wants to merge 1 commit into
arco-design:mainfrom
Mowmowj:fix/trigger-hidden-anchor-reposition

Conversation

@Mowmowj

@Mowmowj Mowmowj commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Types of changes

  • New feature
  • Bug fix
  • Enhancement
  • Component style change
  • Typescript definition change
  • Documentation change
  • Coding style change
  • Refactoring
  • Test cases
  • Continuous integration
  • Breaking change
  • Others

Background and context

When a trigger element is hidden (e.g. display: none) while its popup is still visible or fading out, the popup jumps to the top-left corner of the viewport.

A common real-world case: a hover-revealed edit icon inside a table row, wrapped in <a-tooltip>. On mouseleave the row's :hover state is lost and the icon becomes display: none immediately, while the tooltip is still fading out. Any reposition during that window (onUpdated, resize observer, scroll update) measures the hidden trigger via getBoundingClientRect(), which returns an all-zero rect, and the popup is moved to the viewport corner.

Solution

In updatePopupStyle(), when not in alignPoint mode, skip the reposition and keep the last valid position if the trigger element measures as an all-zero rect (the signature of a hidden element). alignPoint mode is unaffected since it positions from the mouse point, not the element rect.

How is the change tested?

Added a regression test in components/trigger/__test__/index.test.ts: mock the trigger's getBoundingClientRect with a real rect, open the popup, then swap the mock to an all-zero rect and force a reposition — the popup style must stay unchanged. The test fails without the fix (popup style becomes top: 0px) and passes with it.

Changelog

Component Changelog(CN) Changelog(EN) Related issues
trigger 修复触发元素隐藏时弹出层跳到视口角落的问题 Fix popup jumping to the viewport corner when the trigger element is hidden

Checklist:

  • Test suite passes (npm run test)
  • Provide changelog for relevant changes (e.g. bug fixes and new features) if applicable.
  • Changes are submitted to the appropriate branch (e.g. features should be submitted to feature branch and others should be submitted to main branch)

When the trigger element becomes display:none while the popup is still
visible or fading out (e.g. a hover-revealed icon inside a table row),
getBoundingClientRect() measures an all-zero rect and repositioning
against it moves the popup to the viewport corner. Skip the reposition
and keep the last valid position when the anchor rect is collapsed.
@codesandbox

codesandbox Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

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