diff --git a/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DragEndEvent.java b/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DragEndEvent.java
index d400c6ab70d..493a7a9df59 100644
--- a/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DragEndEvent.java
+++ b/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DragEndEvent.java
@@ -76,11 +76,30 @@ public DropEffect getDropEffect() {
/**
* Returns whether the drop event succesful or was it cancelled or didn't
* succeed. This is a shorthand for {@code dropEffect != NONE}.
- *
+ * NOTE: For Edge, Safari and IE11 this method will always
+ * report false
due to bugs in the browsers!
+ *
+ * @deprecated replaced with {@link #isSuccessful()} since 2.1 (v14.1), this
+ * method will be removed later.
* @return {@code true} if the drop event succeeded, {@code false}
* otherwise.
*/
+ @Deprecated
public boolean isSuccesful() {
+ return isSuccessful();
+ }
+
+ /**
+ * Returns whether the drop event succesful or was it cancelled or didn't
+ * succeed. This is a shorthand for {@code dropEffect != NONE}.
+ * NOTE: For Edge, Safari and IE11 this method will always
+ * report false
due to bugs in the browsers!
+ *
+ * @return {@code true} if the drop event succeeded, {@code false}
+ * otherwise.
+ * @since 2.1
+ */
+ public boolean isSuccessful() {
return getDropEffect() != DropEffect.NONE;
}
diff --git a/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DragSource.java b/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DragSource.java
index 8c531fe56bd..a748427c730 100644
--- a/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DragSource.java
+++ b/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DragSource.java
@@ -142,15 +142,27 @@ default T getDragSourceComponent() {
return (T) this;
};
+ @Override
+ default Element getElement() {
+ return getDragSourceComponent().getElement();
+ }
+
/**
* Returns the element where the {@code draggable} attribute is applied,
* making it draggable by the user. By default it is the element of the
* component returned by {@link #getDragSourceComponent()}.
- *
+ *
+ * Override this method to provide another element to be draggable instead + * of the root element of the component. + * * @return the element made draggable + * @since 2.1 */ - @Override - default Element getElement() { + /* + * Implementation note: this is added so that user can change the draggable + * element to be something else than the root element of the component. + */ + default Element getDraggableElement() { return getDragSourceComponent().getElement(); } @@ -166,9 +178,13 @@ default void setDraggable(boolean draggable) { } if (draggable) { // The attribute is an enumerated one and not a Boolean one. - getElement().setProperty("draggable", Boolean.TRUE.toString()); - getElement().executeJavaScript("window.Vaadin.Flow.dndConnector" - + ".activateDragSource($0)", getElement()); + getDraggableElement().setProperty("draggable", + Boolean.TRUE.toString()); + getDraggableElement() + .executeJavaScript( + "window.Vaadin.Flow.dndConnector" + + ".activateDragSource($0)", + getDraggableElement()); // store & clear the component as active drag source for the UI Registration startListenerRegistration = addDragStartListener( event -> getDragSourceComponent().getUI() @@ -187,9 +203,11 @@ default void setDraggable(boolean draggable) { DndUtil.END_LISTENER_REGISTRATION_KEY, endListenerRegistration); } else { - getElement().removeProperty("draggable"); - getElement().executeJavaScript("window.Vaadin.Flow.dndConnector" - + ".deactivateDragSource($0)", getElement()); + getDraggableElement().removeProperty("draggable"); + getDraggableElement().executeJavaScript( + "window.Vaadin.Flow.dndConnector" + + ".deactivateDragSource($0)", + getDraggableElement()); // clear listeners for setting active data source Object startListenerRegistration = ComponentUtil.getData( getDragSourceComponent(), @@ -212,7 +230,7 @@ default void setDraggable(boolean draggable) { * @return {@code true} draggable, {@code false} if not */ default boolean isDraggable() { - return getElement().hasProperty("draggable"); + return getDraggableElement().hasProperty("draggable"); } /** @@ -254,6 +272,14 @@ default Object getDragData() { *
* By default the value is {@link EffectAllowed#UNINITIALIZED} which is * equivalent to {@link EffectAllowed#ALL}. + *
+ * NOTE: The effect should be set in advance, setting it after the + * user has started dragging and the {@link DragStartEvent} has been fired + * is too late - it will take effect only for next drag operation. + *
+ * NOTE 2: Edge, Safari and IE11 will allow the drop to occur even when + * the effect allowed does not match the drop effect set on the drop target. + * Chrome and Firefox prevent the drop if those do not match. * * @param effect * Effects to allow for this draggable element. Cannot be {@code @@ -266,7 +292,8 @@ default void setEffectAllowed(EffectAllowed effect) { if (effect == null) { throw new IllegalArgumentException("Allowed effect cannot be null"); } - getElement().setProperty(DndUtil.EFFECT_ALLOWED_ELEMENT_PROPERTY, + getDraggableElement().setProperty( + DndUtil.EFFECT_ALLOWED_ELEMENT_PROPERTY, effect.getClientPropertyValue()); } @@ -278,7 +305,7 @@ default void setEffectAllowed(EffectAllowed effect) { * @return effects that are allowed for this draggable element. */ default EffectAllowed getEffectAllowed() { - return EffectAllowed.valueOf(getElement().getProperty( + return EffectAllowed.valueOf(getDraggableElement().getProperty( DndUtil.EFFECT_ALLOWED_ELEMENT_PROPERTY, EffectAllowed.UNINITIALIZED.getClientPropertyValue() .toUpperCase(Locale.ENGLISH))); diff --git a/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DropTarget.java b/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DropTarget.java index 73dde9f152b..9ce2d9ff7e1 100644 --- a/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DropTarget.java +++ b/flow-dnd/src/main/java/com/vaadin/flow/component/dnd/DropTarget.java @@ -184,7 +184,7 @@ default boolean isActive() { *
* NOTE: If the drop effect that doesn't match the effectAllowed of the
* drag source, it DOES NOT prevent drop on IE11 and Safari! For FireFox and
- * Chrome the drop is prevented if there they don't match.
+ * Chrome the drop is prevented if the properties don't match.
*
* @param dropEffect
* the drop effect to be set or {@code null} to not modify
diff --git a/flow-dnd/src/test/java/com/vaadin/flow/component/dnd/DropTargetTest.java b/flow-dnd/src/test/java/com/vaadin/flow/component/dnd/DropTargetTest.java
index 04844a7b73a..9223e69098f 100644
--- a/flow-dnd/src/test/java/com/vaadin/flow/component/dnd/DropTargetTest.java
+++ b/flow-dnd/src/test/java/com/vaadin/flow/component/dnd/DropTargetTest.java
@@ -19,7 +19,9 @@
import java.util.concurrent.atomic.AtomicReference;
import com.vaadin.flow.component.Component;
+import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.ComponentUtil;
+import com.vaadin.flow.component.HasComponents;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dnd.internal.DndUtil;
import com.vaadin.flow.router.RouterLink;
@@ -30,7 +32,8 @@
public class DropTargetTest {
@Tag("div")
- class TestComponent extends Component implements DropTarget