-
Notifications
You must be signed in to change notification settings - Fork 166
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
fix: attach element when used in drag source #20490
Conversation
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
eb506c0
to
deaf865
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no strong opinion should the framework add the component by it's own or delegate this to projects. We have agreed that we just document this.
However, with this change, the Flow allows to tune how the component is attached.
Thus, I like this change - to have a default and provide an ability to customise it.
LoggerFactory.getLogger(DragSource.class).info( | ||
"Attaching child to dom in position -100,-100. Consider adding the component manually to not get overlapping components on drag for element."); | ||
getDraggableElement().appendChild(dragElement); | ||
Style style = dragElement.getStyle(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure that appended element does not show up and does not affect DOM unless being dragged, it should probably have display: none
by default and change to display: block
automatically on drag start event before setting the drag element. And reset back when stopped dragging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to work. Tested with the following example:
Div dragBox = new Div("Drag box");
DragSource<Div> dragSource = DragSource.create(dragBox);
dragSource.setDraggable(true);
Button button = new Button("Button");
dragSource.setDragImage(button);
add(dragBox);
It doesn't show anything.
Though it works once I configure it manually:
Div dragBox = new Div("Drag box");
DragSource<Div> dragSource = DragSource.create(dragBox);
dragSource.setDraggable(true);
Button button = new Button("Button");
add(button);
Element element = button.getElement();
Style style = element.getStyle();
style.set("position", "absolute");
style.set("top", "-100px");
style.set("left", "-100px");
// style.set("display", "none"); //also works even if hidden
dragSource.setDragImage(button);
add(dragBox);
LoggerFactory.getLogger(DragSource.class).info( | ||
"Attaching child to dom in position -100,-100. Consider adding the component manually to not get overlapping components on drag for element."); | ||
getDraggableElement().appendChild(dragElement); | ||
Style style = dragElement.getStyle(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to work. Tested with the following example:
Div dragBox = new Div("Drag box");
DragSource<Div> dragSource = DragSource.create(dragBox);
dragSource.setDraggable(true);
Button button = new Button("Button");
dragSource.setDragImage(button);
add(dragBox);
It doesn't show anything.
Though it works once I configure it manually:
Div dragBox = new Div("Drag box");
DragSource<Div> dragSource = DragSource.create(dragBox);
dragSource.setDraggable(true);
Button button = new Button("Button");
add(button);
Element element = button.getElement();
Style style = element.getStyle();
style.set("position", "absolute");
style.set("top", "-100px");
style.set("left", "-100px");
// style.set("display", "none"); //also works even if hidden
dragSource.setDragImage(button);
add(dragBox);
flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DragSource.java
Outdated
Show resolved
Hide resolved
Log attach as debug now that the Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
Quality Gate passedIssues Measures |
Added a workaround to docs, while this is being investigated. vaadin/docs#3936 |
It was my fault, I had .v-dragged {
opacity: 0;
} leftover css in my test project that ofc made things worse. |
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