-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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(CdkDragDrop): preview position is incorrect when inside of a popover using translate #28889
Comments
I think that this is a duplicate of #28864. I have it my TODO to add a note for |
@crisbeto It does look like this is a duplicate of that issue. I agree that browser vendors have not given cdk a good way to solve this problem. Unfortunately to apply the workaround of attaching to body would result in breaking the cascade and requires the consumer of this API to do its own set of hacks to apply what would otherwise be inherited styles. |
Would it be an option to put a container for the inside the list and then have the preview be projected into it? Something like
|
I appreciate the attempted workaround but all of the content in question is inside of a popover type element that positions itself using fixed and transform. Because of this and the way the spec is written for fixed positioning I do not think there is a straight-forward way to break the container out of being constrained. From MDN
It is possible I am misunderstanding the provided workaround but how interpreted it was the following <!-- does the fixed position + transform thing to position itself on screen -->
<my-popover-element>
<!-- sets up some desired styles that are to be inherited -->
<div cdkDropList>
<!-- Unfortunately this is constrained to the bounds of my-popover-element because of its use of transform -->
<div style="position: fixed; top: 0; bottom: 0; left: 0; right: 0;" #previewContainer></div>
<div cdkDrag [cdkDragPreviewContainer]="previewContainer"></div>
</div>
</my-popover-element> The only options I see in this case are the following
I must admit none of these options sound great. |
The example is more or less what I was imagining. I was also thinking if it wouldn't be possible to put the transform on something else that's not a parent of the preview container, but I realize that it might be tricky. And yeah, it's unfortunate that this is the way they implemented the stacking context for fixed elements... I think the only viable workaround would be to create a native popover element dynamically (e.g. |
I'll reopen this so we can try to use native popovers for the preview element. |
…preview Wraps the preview element in a native popover which allows it to always be rendered on top of everything and to avoid issues when the parent element has a `transform`. Fixes angular#28889.
…preview Wraps the preview element in a native popover which allows it to always be rendered on top of everything and to avoid issues when the parent element has a `transform`. Fixes #28889.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Is this a regression?
The previous version in which this bug was not present was
No response
Description
Currently if you are using cdk drag with a preview attached to its parent, and the parent is inside of a popover type element that uses absolute positioning and translate transformation then the preview artifact appears in the wrong location.
This appears to be happening because the fixed position is unable to break out of its container due to a parent element having a transform property attached. Based on MDN this appears to be the expected behavior.
Switching to use the global cdkDragPreviewContainer position works around this issue but then breaks styling because the preview element is removed from the DOM structure controlling style.
Reproduction
StackBlitz link: https://stackblitz.com/edit/stackblitz-starters-1zhux8?file=src%2Fmain.ts
Steps to reproduce:
Expected Behavior
Preview element should be at the same position as the mouse pointer
Actual Behavior
Preview element is several pixels to the right and bottom on the cursor.
Environment
The text was updated successfully, but these errors were encountered: