-
Notifications
You must be signed in to change notification settings - Fork 262
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
Add ability to render native drag preview in context of specific element. #184
Comments
It is already supported, so please take the time to explore the documentation, existing issues, and discussions before creating a new issue. There may be a solution: #121 (comment) |
Thankyou for the suggestion but I don't believe you've understood this issue. I've already read many similar discussions to that where you have pointed to that technique and I already have experience using non-native custom drag previews. Your example was very useful for helping learn how to use non-native drag previews with pragmatic drag and drop, and is probably the best solution for many use-cases because it gives the developer the most control. So thank you for putting it together. However, that is not what this issue is about. It is about using the native drag preview. The preview does not need to change once it is generated, I just want to be able to have the right css context for generating it in the first place. I can put together a simple demo if you don't understand the use case or why it is important. |
@olivercoad I found a workaround that could be useful to you. When calling So what you can do is following:
And here is an example: const customContainer = document.querySelector("#some-id");
let renderContainer = null;
draggable({
element: yourElement,
onGenerateDragPreview: ({ nativeSetDragImage, location }) => {
setCustomNativeDragPreview({
nativeSetDragImage,
render: ({ container }) => {
renderContainer = container;
customContainer?.appendChild(renderContainer);
},
});
},
onDragStart() {
if (renderContainer) {
document.body.appendChild(renderContainer);
}
},
onDrop() {
if (renderContainer) {
document.body.appendChild(renderContainer);
}
},
}) This is hacky, but it works 🤷♂ |
When generating the custom drag preview, the
container
is added directly tobody
. This means it inherits the CSS state of body, including CSS variables, font,currentColor
etc.I'd love the option to provide an alternative element to
document.body
to mount the container to, so that it can inherit the desired CSS state from the context of where the dragged element is.The main reason I want this is so that it can get use the css variables from the theme, which aren't present on the body.
Because
container
isposition: fixed
, it will still render in the correct place.Potential gotchas to look out for are when the element:
display: none
Proposed change
The text was updated successfully, but these errors were encountered: