1. Domino UI
  2. Components
  3. Drag and Drop
Top Basic Docs

Drag and Drop

Draggable

Represents an element that can be dragged by users.

This utility makes any given element draggable and provides an interface for interacting with the drag-and-drop process.

Example usage:

 
 Draggable< MyElement>  draggable = Draggable.of(myElementInstance);
 draggable.detach(); // To stop the element from being draggable
 

E

the type of the draggable element which should implement IsElement

Drag source

Manages a collection of draggable elements providing functionality to add and remove them.

This class maintains a map of draggable elements and offers methods to dynamically manage which elements are draggable at a given time. Example usage:

 
 DragSource source = new DragSource();
 Draggable< MyElement>  draggable = Draggable.of(myElementInstance);
 source.addDraggable(draggable);
 source.removeDraggable(draggable.getId());
 

Drop zone

A manager for drop targets in a Drag-and-Drop system.

The DropZone class allows the easy addition and removal of drop targets. It provides functionality to manage the dropping of dragged elements on registered targets. Example usage:

 
 DropZone zone = new DropZone();
 zone.addDropTarget(myHtmlElement, draggableId -> DomGlobal.console.info("Dropped: " + draggableId));
 

Examples

Basic usage sample

API Docs: Draggble

Static methods

public static Draggable<E> of(E element)
Creates a draggable instance for the specified element.

element

the element to be made draggable

E

the type of the element



Returns:

a new Draggable instance

public static Draggable<E> of(E element, Consumer<E> dragStartListener)
Creates a draggable instance for the specified element with a drag start listener.

element

the element to be made draggable

dragStartListener

listener for the drag start event

E

the type of the element



Returns:

a new Draggable instance

public static Draggable<E> of(String id, E element)
Creates a draggable instance for the specified element with a unique identifier.

id

unique identifier for the draggable element

element

the element to be made draggable

E

the type of the element



Returns:

a new Draggable instance

public static Draggable<E> of(String id, E element, Consumer<E> dragStartListener)
Creates a draggable instance for the specified element with a unique identifier and drag start listener.

id

unique identifier for the draggable element

element

the element to be made draggable

dragStartListener

listener for the drag start event

E

the type of the element



Returns:

a new Draggable instance

Public methods

public DraggableConfig getConfig()


Returns:

Draggble item DraggableConfig

public void setConfig(DraggableConfig config)
Sets the configuration for the draggble item, if null use a default config

config

DraggableConfig

public void detach()
Detaches the draggable feature from the element.
public String getId()
Returns the unique identifier of the draggable element.

Returns:

the unique identifier

API Docs: DragSource

Public methods

public void addDraggable(Draggable<?> draggable)
Adds a new Draggable element to the manager.

draggable

the draggable element to be added

public void removeDraggable(String id)
Removes a Draggable element from the manager using its ID.

If an element with the provided ID is found, it is first detached (made non-draggable) and then removed from the manager.

id

the unique identifier of the draggable element to be removed

API Docs: DropZone

Public methods

public void addDropTarget(HTMLElement element, DropListener dropListener)
Registers an HTMLElement as a drop target with a specified DropListener .

element

the HTML element to register as a drop target

dropListener

the listener that will be invoked upon a drop event

public void addDropTarget(IsElement<? extends HTMLElement> element, DropListener dropListener)
Registers an IsElement as a drop target with a specified DropListener .

element

the IsElement to register as a drop target

dropListener

the listener that will be invoked upon a drop event

public void removeDropTarget(HTMLElement element)
Unregisters an HTMLElement from being a drop target.

element

the HTML element to unregister as a drop target

public void removeDropTarget(IsElement<? extends HTMLElement> element)
Unregisters an IsElement from being a drop target.

element

the IsElement to unregister as a drop target

We are a group of passionate people who love what we do

Donate & Support Us