Incorrect calculation of nextOffsetY
@zombieJ ci sta già lavorando.
Dal 30/3/2023.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
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!
- Lingua principale
- TypeScript
- Stelle
- 392
- Fork
- 250
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di react-component/trigger
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
react-component/trigger#593 · 1 reazione ·
-
useAlign reuses a stale flip decision after the viewport changes (popup stays flipped until reopen)Forse già presa @SXongin l’ha presa 34 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 30/100
react-component/trigger#651 ·
-
Does not work when rendered inside an iframeForse già presa @PinkChampagne17 l’ha presa 185 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
react-component/trigger#623 ·
-
useAlign.js: inline style reset to 0 is silently overridden under prefers-reduced-motion CSS (CSSTransition interpolation)Forse già presa @baofuen l’ha presa 144 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
react-component/trigger#618 · 1 commento ·
-
`collectScroller` is not working as expected when the element is in shadow DOMForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
react-component/trigger#555 ·
Tutte le issue di react-component/trigger
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
tashfeenahmed/freellmapi#2305 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
prime-radiant-inc/evener#8335 ·
I maintainer di solito rispondono entro 1 giorno
-
Calendar: a range's preview stays on the last day pointed at after the pointer leaves the daysAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
vercel-labs/ui#1921 ·
I maintainer di solito rispondono entro 1 giorno
-
docs: a new board's default grant names development, Vercel's API seeds preview and productionAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 65/100
microsoft/monaco-editor#5626 ·
I maintainer di solito rispondono entro 1 giorno