Skip to content

Drag & Drop ​

A drag and drop building block based on the HTML Drag and Drop API.

Type: Building Block

Available in: App Page · Home Page · Record Page

Read on Medium ​

Implement Drag & Drop with LWC

Implement Drag & Drop with LWC

Attributes ​

NameTypeDefaultDescription
itemsArray or stringThe items to drag, as an array or a JSON string. Each item has a unique id and a label. Twelve demo elements are used until this is set.

Events ​

NameDetailDescription
itemdropA copy of the dropped itemFired when an item was dropped.

Usage ​

html
<c-drag-and-drop items={items} onitemdrop={handleItemDrop}></c-drag-and-drop>

Drag an item into the dropzone and it moves to the datatable there. New items start over with an empty dropzone. If a string is not valid JSON, the component shows an error message.

Custom Labels ​

The texts users see are Custom Labels, so they can be translated in Setup with the Translation Workbench. Copy them together with the component.

NameValue
DragAndDrop_DragDrag
DragAndDrop_DraggableElementsDraggable Elements
DragAndDrop_DropDrop
DragAndDrop_DropzoneDropzone
DragAndDrop_ElementElement
DragAndDrop_IdId
DragAndDrop_InvalidItemsThe items could not be displayed because they are not valid JSON.
DragAndDrop_LabelLabel
ErrorAlert_ErrorError

Component Dependencies ​

NameTypeDescription
errorAlertLWCInline alert that shows error messages to the user.
labelUtilsLWCShared function to fill the placeholders of Custom Labels.

Released under the MIT License. · llms.txt for AI agents