Skip to Content

UI5ers Buzz #32: Drag-and-Drop is now enabled for all UI5 Controls

One of the most powerful interaction design pattern available to developers is Drag-and-Drop.

Drag-and-Drop allows moving, reordering and applying actions to objects. This makes it a simple and intuitive action, in line with Fiori and users’ expectations.

With SAPUI5 version 1.56, a new dragAndDrop aggregation with multiplicity 0..n is now available for every Control in UI5 and it can be used to configure complete drag-and-drop scenarios via DragInfoDropInfo or DragDropInfo without really giving it much thought!

Let’s briefly have a look at this simple but powerful drag-and-drop condiguration objects.

 

 

DragInfo can be used just to allow dragging when drop target is not known or not owned. Additional draggable checks can be done at the dragStart event and default can be prevented.

DropInfo can be used as a general drop target. Incoming data may need to be validated at the dragEnter event. Applications should just implement the drop event.

DragDropInfo can be used when the drag source and the drop target are tightly coupled and both are known. The most common use-case is enablement own aggregations.

Both DragInfo and DropInfo offers groupName property. If this property is specified, then the DropInfo object will only interact with the relevant DragInfo objects within the same group.

Let’s don’t make this attractive topic boring with long texts. Let’s see a little code snippet first.

 Enable reordering of the items inside the List
 <List items=”{/Products}”>
    <dragDropConfig>
        <dnd:DragDropInfo
            sourceAggregation=”items”
            targetAggregation=”items”
            dropPosition=”Between”
            drop=”onReorderItems”/>
    </dragDropConfig>
 </List>

 

Now let’s see Drag-and-Drop in action.

 

If you could follow all the links above that means you’ve learned already a lot. Now it is time for fun! 🥳 Yes… UI5 is not only for enterprise-ready web applications, sometimes just for jun. Let’s play a little drag-and-drop game and don’t hesitate to hack the source code if you cannot solve the puzzle.

 

Here are some useful links if you want to know more about drag-and-drop in UI5.

 

Previous post: UI5ers Buzz #31

Cahit

"Guess who I am?".charAt.call(Number, 1) + (this + "")[9] + [...[...'.....']].length + ``.substr.call(/(?:)/.constructor.name, 3) + alert.name.slice(-3);

 

12 Comments
You must be Logged on to comment or reply to a post.
  • I just love your dragNdrop game 😀 I remember having it as kid as a “real” game …  again addicted to it! Still wonder how you made it in 38 drops …???

    If you would add a highscore to it, then this Web page would become quite busy 😉

    Thanks for the great work!

  • very cool shakes, generic drag’n’drop functionality!

    I almost hesitate to ask…but…how do we test that w/ OPA? Probably there’s already some documentation out there and I just might have missed it.

     

    • Hi Volker, as you can see at the concept slides, UI5 is leveraging the native HTML Drag&Drop API.

       

      This means you can just trigger native events from the control DOM to test the complete drag&drop scenarios. So something like below probably be enough to test most of the use cases.

      function triggerEvent (control, type, options) {
          let event = new DragEvent(type, Object.assign({bubbles: true, cancelable: true}, options));
          control.getDomRef().dispatchEvent(event);
      }

       

      We also had an idea to simulate drag&drop to help keyboard handling, context menu and toolbar buttons that do the equivalent of the drag&drop actions for accessible reasons. Probably this could also be very nice syntatic sugar for testing.

      DnDSim.grab(item1).moveToBottomOf(item5).drop();
      DnDSim.drag(item2).to(item4);

      Thanks for this question now we have one more reason to have this in the framework!

  • I believe the sap.ui.core.HTML component used to support drag-and-drop of standard HTML elements.  Is this still possible with the latest UI5 enhancements?

     

  • Thank you for sharing this blog.

    But i still have a question, even ‘Drag-and-Drop is now enabled for all UI5 Controls’ i still don’t find a way ,for exemple, to drag a Button control or to configure a custom control as droppable.

    Only controls that we can put ‘dragDropConfig’ inside them can be defined as draggable or drappable?

    If yes, is there another solution to go ahead and let my Button draggable for example?

    Thank you a lot.

    Ilyes