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

bug:(@angular/cdk/drag-drop) - Incorrect item position when dragging item in <cdk-drop> - Safari Mobile #13090

Closed
kccsf opened this issue Sep 12, 2018 · 7 comments
Assignees
Labels
area: cdk/drag-drop needs: discussion Further discussion with the team is needed before proceeding P4 A relatively minor issue that is not relevant to core functions
Projects

Comments

@kccsf
Copy link

kccsf commented Sep 12, 2018

Bug, feature request, or proposal:

Bug

What is the expected behavior?

When dragging an item, the dragged item should stay positioned directly beneath your finger (touch device).

What is the current behavior?

When zoomed into a web page (ie having pinched to zoom) on Safari mobile , the dragged item is positioned away from your finger. The higher the zoom level, the further away the dragged item is from your finger.

What are the steps to reproduce?

Behaviour can be seen in the 'Drag&Drop sorting' section after zooming in.
https://beta-angular-material-io.firebaseapp.com/cdk/drag-drop/examples

drag position

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

@angular/cdk 7.0.0-beta.0
@angular/core 6.1.7
typescript 2.9.2
Safari Mobile on iPad A1893 running iOS 11.3.1 / 11.4.1

@crisbeto
Copy link
Member

I believe this is the same issue as #10924. When the browser is zoomed in, it'll report different numbers to getBoundingClientRect and, as far as I'm aware, there's no way for us to account for it.

@kccsf
Copy link
Author

kccsf commented Sep 13, 2018

I have this working using an idea found here (credit to the author):
https://stackoverflow.com/questions/52085998/how-to-position-a-fixed-location-element-on-ios-browser-when-zoomed

I do agree with his point that it feels pretty kludgey so the jury is out on whether you consider the method one that can be used. In case not but it helps others - here is some code (I was just editing drag-drop.es5.js directly whilst working on a solution):

Added the following function:

CdkDrag.prototype._setOffset =
    function () {
      this._offset = [0, 0];
      if (/iP(ad|hone|od).+Version\/[\d\.]+.*Safari/i.test(navigator.userAgent)) {
        var elem = document.createElement('div');
        document.body.appendChild(elem);
        elem.style.cssText = 'position:fixed; top: 0; left: 0;';
        var rect = elem.getBoundingClientRect();
        document.body.removeChild(elem);
        this._offset = [rect.left, rect.top];
      }
    };

Then called the function from _createPreviewElement prior to the (second) _setTransform (the one called due to there being no _previewTemplate).

The offset is then used in _setTransform:
element.style.transform = "translate3d(" + (x - this._offset[0]) + "px, " + (y - this._offset[1]) + "px, 0)";

Credits to the author of the device test I grabbed also:
https://coderwall.com/p/ktrbhq/detect-mobile-safari

This has been tested on:
iPad: iOS 9.2 /11.4.1
iPhone: iOS 10.3.3
Does not (I wouldn't expect it to due to the UA test) appear to have broken:
Safari: 11.0
Chrome (Windows): 68.0.3440.106 / 69.0.3497.92
Chrome (Android): 69.0.3497.91
Edge: 42.17134.1.0
FF Quantum: 62.0

@crisbeto
Copy link
Member

Thanks for looking into it, but I'm not sure whether that's a feasible solution, because we'd have to do it every time you start dragging, otherwise we risk it being inaccurate, in addition to not being the cheapest calculation to make. I think that this is a non-issue, because responsive apps disable zooming anyway.

@kccsf
Copy link
Author

kccsf commented Sep 15, 2018 via email

@doublemcz
Copy link

I also experienced this issue when CSS zoom property is set to whenever but 1.

@mmalerba mmalerba added the needs triage This issue needs to be triaged by the team label May 20, 2020
@crisbeto crisbeto added area: cdk/drag-drop needs: discussion Further discussion with the team is needed before proceeding P4 A relatively minor issue that is not relevant to core functions and removed needs triage This issue needs to be triaged by the team labels May 25, 2020
@crisbeto crisbeto added this to Triaged in triage #1 via automation May 25, 2020
@mmalerba mmalerba assigned mmalerba and unassigned crisbeto Dec 2, 2022
@mmalerba
Copy link
Contributor

mmalerba commented Dec 2, 2022

Closing as infeasible per the discussion above

@mmalerba mmalerba closed this as completed Dec 2, 2022
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: cdk/drag-drop needs: discussion Further discussion with the team is needed before proceeding P4 A relatively minor issue that is not relevant to core functions
Projects
No open projects
triage #1
  
Triaged
Development

No branches or pull requests

4 participants