react-spectrum icon indicating copy to clipboard operation
react-spectrum copied to clipboard

useOverlayPosition regression for non-viewport boundary/container

Open jaslong opened this issue 1 year ago โ€ข 1 comments

Provide a general summary of the issue here

I am using useOverlayPosition to display a non-viewport boundary/container (with same offset and size). Previously, the position works as expected, but in the latest versions, the cross axis offset is wrong.

Bug occurs in [email protected]. Also tested with [email protected].

๐Ÿค” Expected Behavior?

Overlay shows up in the boundary

๐Ÿ˜ฏ Current Behavior

Overlay shows up outside of the boundary on the cross axis

๐Ÿ’ Possible Solution

I'm fairly confident this bug was caused by https://github.com/adobe/react-spectrum/pull/5660.

Specifically, I think there's an incorrect assumption being made, that boundaryStartEdge and boundaryEndEdge are values relative to the visual viewport. In my app, I found that these values are relative to the boundary's offset instead. We have padding 12px and width 300px, so boundaryStartEdge=12 and boundaryEndEdge=288.

Then in the following lines, startEdgeOffset and endEdgeOffset subtract the boundary's cross axis offset. In my app, the boundary/container are the same offset/size and are on the right side of the viewport, so the boundary's cross axis offset was very large (e.g. 800px), resulting in very negative values, like startEdgeOffset=-700 and endEdgeOffset=-600.

Finally, this results in the first if (startEdgeOffset < boundaryStartEdge) branch to evaluate to true, returning a delta of boundaryStartEdge - startEdgeOffset = (12) - (-700) = 712, pushing the overlay far off the boundary.

My guess is, the correct code is to stop subtracting the boundary's cross axis offset. This worked for me, but I'm not sure it works in all cases.

๐Ÿ”ฆ Context

No response

๐Ÿ–ฅ๏ธ Steps to Reproduce

Sorry I don't have time to set up a minimal test case right now, but I wanted to raise this issue in case others were encountering it since it's tricky to debug.

Version

[email protected], [email protected]

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

MacOS

๐Ÿงข Your Company/Team

No response

๐Ÿ•ท Tracking Issue

No response

jaslong avatar May 06 '24 08:05 jaslong

Thanks for reporting this, will have to revisit that logic. I believe you are right about boundaryStartEdge and boundaryEndEdge, not sure why I didn't do that

LFDanLu avatar May 18 '24 00:05 LFDanLu