Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scroll): prevent wrong offset when the scroll is on the html element #2499

Conversation

VincentMolinie
Copy link
Contributor

@VincentMolinie VincentMolinie commented Oct 11, 2023

Description

Having scroll on the html element was increasing the offset because that element behave a bit differently, meaning that the scroll was included in the position of the html element.
So we had basically position like

{ top: -150, left: 0 }

But if it's the html element in our case we were always expecting 0

Checklist

  • Created tests which fail without the change (if possible)
  • All tests passing (yarn test)
  • Extended the README / documentation, if necessary

Issues related

Fix #2491

const transformParentRect = transformParent.getBoundingClientRect();
// We need to be careful here as the html element actually also includes scroll
// so in this case we always need to ignore it
const transformParentRect = transformParent === document.documentElement ? { top: 0, left: 0 } : transformParent.getBoundingClientRect();
Copy link
Member

@adumesny adumesny Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this assuming here that the entire doc is scrollable, but it could be any parent div in between. I thought we had code to detect scrolled parent and take that into content... I would look back at the original code that handled any level fine (just didn't scale)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes actually you are right the issue is bigger than that. I will fix it 😄

@VincentMolinie
Copy link
Contributor Author

Okey I tested pretty much everything and I couldn't find issue. It should be good 🤞

@adumesny
Copy link
Member

adumesny commented Oct 14, 2023

thanks for this fix but #2498 #2497 remains and I have to revert all your changes for now as 9.3 is worst, until you can prove your entire new code path is better than what it replaced. would have been much better to add scale to existing code instead of hunting/debugging all the issues you have now created.

Update: I have reverted in #2504 which you would need to pick again if you insist on your new code path and can prove it is better than adding scale to the old code path.

Vincent Molinié and others added 3 commits October 16, 2023 10:01
gridstack#2263)

* fix(drag): place the element dragged always below the mouse

* fix: review fixes

* fix: fix data transfer demo

* fix: review fixes

* fix: fix position according to first transform parent

* review fixes

* review fixes

* review fixes

* fix: fix the refacto

---------

Co-authored-by: Vincent Molinié <vincent.m@forestadmin.com>
@VincentMolinie VincentMolinie force-pushed the fix/scroll-on-html-element branch from ad024a9 to cc005fc Compare October 16, 2023 08:02
@VincentMolinie
Copy link
Contributor Author

This one is fixed too: #2498 but like I told you for the other one. I don't see how it is related. It seems more related to a PR that is 3 weeks old, not mine

@adumesny
Copy link
Member

adumesny commented Oct 22, 2023

going with #2515 instead of your re-write (what I had asked all along).

@adumesny adumesny closed this Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid drag offset when page scrolled after 9.3
2 participants