Incorrect calculation of nextOffsetY
@zombieJ 已经在做这个了。
开始于 2023年3月30日。
评估
这个 Issue 还没有评估数据。
描述
When recalculating nextOffsetY when popup goes beyond the viewport boundaries incorrect calculations occur.
I see problems in these lines:
https://github.com/react-component/trigger/blob/a73beef20376e3e32ecb918a0c1fbb0cdabb42f3/src/hooks/useAlign.ts#L313
https://github.com/react-component/trigger/blob/a73beef20376e3e32ecb918a0c1fbb0cdabb42f3/src/hooks/useAlign.ts#L327
Let's analyze each line separately.
nextOffsetX = targetAlignPointTL.x - popupAlignPointBR.x - popupOffsetX;
suppose
the target's bounding box is
{
width: 200px
left: 300px
right: 500px
}
the popup's bounding box is
{
width: 600px
left: 0px
right: 600px
}
first popup calculation without flip recalculation
{
width: 600px
left: 300px
right: 900px
}
x viewport border for example is 600px
Our popup climbs out of the border, so we implement the recalculation of nextOffsetX.
targetAlignPointTL.x = 300px
popupAlignPointBR.x = 600px
popupOffsetX = 0
nextOffsetX = 300px - 600px - 0 = -300px
Total we get that our popup left offset is -300px
and right 600px - 300px = 300px
And we observe approximately the following picture

In order to get the correct offset, you need to subtract the right coordinate of popup not from the left coordinate of the target, but from the right.
In other words, change targetAlignPointTL to targetAlignPointBR and get
nextOffsetX = targetAlignPointBR.x - popupAlignPointBR.x - popupOffsetX;
The situation is similar with Left to Right
nextOffsetX = targetAlignPointBR.x - popupAlignPointTL.x - popupOffsetX;
if we take fake data
target bb
{
width: 200px
left: 100px
right: 300px
}
popup bb
{
width: 500px
left: 0px
right: 500px
}
popup calculated bb
{
width: 500px
left: -200px
right: 300px
}
viewport left border 0px
popupOffsetX = 0px
then substituting into the current formula we get
nextOffsetX = 300px - 0px - 0px = 300px
Popup offset is 300px this is the right border of the target.
Why not just take the left offset of target and make it equal to nextOffsetX?
Well, or as a last resort, add the right border of the target to the existing offset
nextOffsetX = nextOffsetX + targetAlignPointBR.x = -200px + 300px = 100px
We will get the same 100px
In general, the problem is on the face and it brings a lot of inconvenience. Please pay attention to it!
- 主要语言
- TypeScript
- 星标
- 392
- 派生
- 250
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
react-component/trigger 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
react-component/trigger#593 · 1 个 reaction ·
-
useAlign reuses a stale flip decision after the viewport changes (popup stays flipped until reopen)可能已有人在做 @SXongin 于 34 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 30/100
react-component/trigger#651 ·
-
Does not work when rendered inside an iframe可能已有人在做 @PinkChampagne17 于 185 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 58/100
react-component/trigger#623 ·
-
useAlign.js: inline style reset to 0 is silently overridden under prefers-reduced-motion CSS (CSSTransition interpolation)可能已有人在做 @baofuen 于 144 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 65/100
react-component/trigger#618 · 1 条评论 ·
-
`collectScroller` is not working as expected when the element is in shadow DOM可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 3/5 1-2 天 新手友好度 42/100
react-component/trigger#555 ·
查看 react-component/trigger 的全部 Issue
相似的 Issue
-
agent/guide documentation help wanted stage/010-actionable
难度 1/5 1 小时以内 新手友好度 82/100
kubestellar/console-marketplace#1101 ·
维护者通常 1 天内回复
-
Java Edition Tests
难度 2/5 1-3 小时 新手友好度 72/100
JSPrismarine/JSPrismarine#4178 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
totec448-spec/chat-on-steroids#2394 ·
维护者通常 1 天内回复
-
github_actions
难度 2/5 1-3 小时 新手友好度 70/100
StellarHyperion/stellarhyperion-backend#499 ·
维护者通常 1 天内回复