[Drag and Drop] Provide an input from where the preview will be attached
Bug, feature request, or proposal:
A new input to provide a DOM element to attach the cdkDragPreview element
What is the expected behavior?
Provide a new input to select a DOM element different than the body to attach the cdkDragPreview element
What is the current behavior?
There is no way to attach the cdkDragPreview item (default or not) to a different element than the body
What are the steps to reproduce?
- Start a dragging on an element
- The preview of the dragged element is attached as a child of the body
What is the use-case or motivation for changing an existing behavior?
We are using Angular as a dependency of an inner source project.. And we need to support different themes but the element where the preview is attached could make that the preview item doesn't looks like we expected on some projects because of their particular soluction
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
We are using v7.1.1 of Angular and the rest of their dependencies
Is there anything else we should know?
This should be pretty easy to add, but the problem is that it can cause people's apps to break, if they don't configure it correctly. The reason we put the element inside the body is to avoid issues with overflow: hidden and z-index.
Since you mentioned the primary issue being theming, would it make sense to allow for a custom class to be applied on the preview instead?
mmm, I am trying to figure out how it could break someone else's app.. If the body is defined as the default place to attach the preview then those people that weren't using this new input will not be affected by this change 🤔 But maybe you have deeper knowledge on this that I don't have
I meant that people can break their own apps if they don't use it correctly. In general we want to prevent people shooting themselves in the foot, if we can.
Oh, I understand your point.. So the problem is related with theming and the way we handle it.. Since this is for a inner source that only provides components, it hasn't any javascript logic to handle which theme the user had selected. Then all the styles are applied by css depending on the the selected theme and adding an specific class to the app (currently we are only supporting 2 themes).. And the issue with the preview is that since it is attached to the body, some apps could not being attaching the correct theming class to body or before.. Then, there is not way to have styles recognizing which is the selected one..
Wouldn't adding the theme class to the preview solve the issue though?
We have not access to the selected theme on the components of this library.. The project using the library should be the one at charge of select and communicate in a simple way (css in this case) to the rest of the component which should be the theme to show/use.. Basically, the components this library is providing have not any business logic nor any other logic like knowing the selected theme :/
As we are only using two themes, we are using a common style for both scenarios.. But in an ideal world, this should not be the final implementation
Have quite similar problem. This is related to CSS variables usage. We have a component which is reusable and can be inserted into light or dark elements. It's fully styled using CSS variables, so it has no idea which theme it's using right now, so we cannot apply additional class name to drag preview element. As a result attaching it to body, which doesn't have required CSS variables breaks the styling.
The markup looks like this
<body>
<div class="class-name-with-theme-related-css-variables">
<component-with-drag-and-drop />
</div>
</body>
Combining with https://github.com/angular/components/issues/13288 since it's basically the same issue. Also bumping the priority on the initial issue.
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.