Skip to content

Add ability to render native drag preview in context of specific element. #184

Open
@olivercoad

Description

When generating the custom drag preview, the container is added directly to body. 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 is position: fixed, it will still render in the correct place.
Potential gotchas to look out for are when the element:

  • is hidden or display: none
  • has opacity
  • has other things above it in the stacking context

Proposed change

export function setCustomNativeDragPreview({
	render,
	nativeSetDragImage,
	getOffset = defaultOffset,
        containerParent = document.body,
}: {
	getOffset?: GetOffsetFn;
	render: RenderFn;
	nativeSetDragImage: ElementEventPayloadMap['onGenerateDragPreview']['nativeSetDragImage'];
        containerParent?: HTMLElement;
}) {

/* ... */
        // document.body.append(container);
	containerParent.append(container);

/* cleanup */
            // document.body.removeChild(container);
            containerParent.removeChild(container);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions