Incorrect calculation of nextOffsetY
@zombieJ já está trabalhando nisso.
Desde 30/3/2023.
Avaliação
Esta issue ainda não foi avaliada.
Descrição
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!
- Linguagem predominante
- TypeScript
- Estrelas
- 391
- Forks
- 246
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de react-component/trigger
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
react-component/trigger#593 · 1 reação ·
-
Does not work when rendered inside an iframeTalvez já em andamento @PinkChampagne17 assumiu há 126 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 58/100
react-component/trigger#623 ·
-
useAlign.js: inline style reset to 0 is silently overridden under prefers-reduced-motion CSS (CSSTransition interpolation)Talvez já em andamento @baofuen assumiu há 85 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 65/100
react-component/trigger#618 · 1 comentário ·
-
`collectScroller` is not working as expected when the element is in shadow DOMTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 42/100
react-component/trigger#555 ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
react-component/trigger#550 · 1 comentário ·
Todas as issues de react-component/trigger
Issues semelhantes
-
bot:ai-assisted status:untriaged
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
midnightntwrk/midnight-js#1424 ·
Mantenedores costumam responder em até 1 dia
-
enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
mksglu/context-mode#1268 ·
Mantenedores costumam responder em até 5 dias
-
Edit:Abertacheck:failed streams:edit
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 60/100
iptv-org/iptv#54352 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
[Table] reserveSelectedRowOnPaginate=false 时表头全选包含其他页数据Talvez já em andamento @dvd233 assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
Tencent/tdesign-react#4416 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
area:widget bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
interledger/publisher-tools#894 ·
Mantenedores costumam responder em até 1 dia