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

Support for invisible/detached components for setDragImage #20426

Open
mshabarov opened this issue Nov 7, 2024 · 0 comments · May be fixed by #20490
Open

Support for invisible/detached components for setDragImage #20426

mshabarov opened this issue Nov 7, 2024 · 0 comments · May be fixed by #20490
Assignees

Comments

@mshabarov
Copy link
Contributor

Describe your motivation

The recently added Drag Image support is limited to cases, when the component is a visible element in the viewport. The component does not appear during drag, if it's just a detached component:

Div dragBox = new Div("Drag box");
DragSource<Div> dragSource = DragSource.configure(dragBox);
dragSource.setDraggable(true);
dragSource.setDragImage(new Div("Drag Source Image"));
add(dragBox);

see this comment.

setDragImage browser's API states that the element should be visible or added to a DOM, see https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/setDragImage#imgelement.

Describe the solution you'd like

With adding a component to a DOM and offset it like this (just an example), makes it shown as drag image.

add(dragSourceImage);
dragSourceImage.getStyle().set("position", "absolute");
dragSourceImage.getStyle().set("top", "-100px");
dragSourceImage.getStyle().set("left", "-100px");

Vaadin Flow's DnD can integrate some logic that add/hides the component on a page to make the API work.
A bit of hacky solution, There is no other way currently to make it work.

Describe alternatives you've considered

Document possible workarounds that can be applied in projects, but IMO that's a wrong way.

Additional contex

Vaadin 24.6 pre-release.

@mshabarov mshabarov moved this to 🪵Product backlog in Vaadin Flow ongoing work (Vaadin 10+) Nov 7, 2024
@caalador caalador self-assigned this Nov 15, 2024
@caalador caalador moved this from 🟢Ready to Go to ⚒️ In progress in Vaadin Flow ongoing work (Vaadin 10+) Nov 15, 2024
caalador added a commit that referenced this issue Nov 18, 2024
Attach elemnt to dom and move it
outside of the viewport to have it
visible as a drag image.
Image can be used without attaching
to dom. Hidden elements are also
not shown so throw exception
when using one as dragImage.

Fixes #20426
@caalador caalador linked a pull request Nov 18, 2024 that will close this issue
caalador added a commit that referenced this issue Nov 18, 2024
Attach elemnt to dom and move it
outside of the viewport to have it
visible as a drag image.
Image can be used without attaching
to dom. Hidden elements are also
not shown so throw exception
when using one as dragImage.

Fixes #20426
@mshabarov mshabarov moved this from ⚒️ In progress to 🔎Iteration reviews in Vaadin Flow ongoing work (Vaadin 10+) Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🔎Iteration reviews
Development

Successfully merging a pull request may close this issue.

2 participants