trigger icon indicating copy to clipboard operation
trigger copied to clipboard

Fix popup position for point-aligned popups when no mouse position is known

Open philippotto opened this issue 1 year ago • 3 comments

When setting popupVisible of a <Trigger /> to true in a controlled manner, the popup is shown at 0,0 of the current page instead of being placed around its actual target. The reason for this is that the mouse position is initialized to 0, 0 and then passed along to useAlign. This is a regression that was introduced in 848a197. In 7590937 this used to work and it had the exact logic I now re-added.

Within 848a197, the missing null initialization was introduced here: https://github.com/react-component/trigger/commit/848a197f2236f6f5af94cc44e658bebae53837ae#diff-0b5adbfe7b36e4ae2f479291e20152e33e940f7f265162d77f40f6bdb5da7405R310 And here's the conditional passing of the point that was removed: https://github.com/react-component/trigger/commit/848a197f2236f6f5af94cc44e658bebae53837ae#diff-0b5adbfe7b36e4ae2f479291e20152e33e940f7f265162d77f40f6bdb5da7405L542

As a test, I set popupVisible to true in rc-trigger/docs/examples/point.tsx so that the popup is rendered by default.

Before: image

After: image

Would fix https://github.com/ant-design/ant-design/issues/47152.

philippotto avatar Mar 08 '24 14:03 philippotto

Could you add a test case ?

afc163 avatar Mar 11 '24 02:03 afc163

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 97.68%. Comparing base (50ae862) to head (4e66204). Report is 16 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #447   +/-   ##
=======================================
  Coverage   97.68%   97.68%           
=======================================
  Files          13       13           
  Lines         776      776           
  Branches      221      221           
=======================================
  Hits          758      758           
  Misses         18       18           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Mar 11 '24 02:03 codecov[bot]

Could you add a test case ?

I tried, but apparently I'm doing something wrong. You can have a look at this commit: https://github.com/scalableminds/trigger/commit/74b13aae4e875eb1c59b71e43805a5cde5dac71a

Quoting from my comment in that commit:

      // This test does not work at all at the moment, because useAlign calls
      // isVisible on the trigger's target (div with class "point-region").
      // For that div, getBoundingClientRect() always returns a width and height
      // of zero. Therefore, it is interpreted as not visible and useAlign
      // returns ready==false.

If you know an easy fix for this, I can incorporate it. However, I don't have much time diving into this further. Maybe the PR is alright without a test?

philippotto avatar Mar 11 '24 09:03 philippotto