Skip to content

Flex box "align-items" or "justify-content" causes smaller drop area  #1869

Closed

Description

@aquaductape

Describe the bug
List item is unable to be added properly to group container with either flex position properties align-items, justify-content accompanied to flex parent.

To Reproduce
Steps to reproduce the behavior:

  1. Go to group css container that holds the list
  2. Change properties to following
.group {
  display: flex;
  align-items: center;
  justify-content: center;
}

Expected behavior

List item clone ghost to appear in group as soon as cursor enters group and added to group when letting go of item.
This works fine if the group has zero items, but once you try to add another item, it seems that the drag and drop boundary has been cut in half, so you have to drag the item to bottom half in order to drop it.

Peek 2020-07-26 00-37

Information
sortablejs = ^1.10.2

Reproduction
https://jsbin.com/kuhugefinu/1/edit?html,css,js,output

Activity

  1. aquaductape commented on Jul 27, 2020

    @aquaductape
    Author

    Skimming through the source, the reason why the item is able to be detected by an empty sortable, is if the sortable doesn't have any children, then it will be added. However if the sortable has children, it fails the _ghostIsLast conditional, therefore the item isn't added to the sortable when dropping. Once the dragging item is below the half the sortable ( if direction set to "horizontal" ), then ghost item appears properly, then letting go the item is able to be added to the sortable because it passes the _ghostIsLast conditional.

    Sortable/src/Sortable.js

    Lines 1170 to 1195 in 88838bf

    let elLastChild = lastChild(el, options.draggable);
    if (!elLastChild || _ghostIsLast(evt, vertical, this) && !elLastChild.animated) {
    // If already at end of list: Do not insert
    if (elLastChild === dragEl) {
    return completed(false);
    }
    // assign target only if condition is true
    if (elLastChild && el === evt.target) {
    target = elLastChild;
    }
    if (target) {
    targetRect = getRect(target);
    }
    if (onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, !!target) !== false) {
    capture();
    el.appendChild(dragEl);
    parentEl = el; // actualization
    changed();
    return completed(true);
    }
    }

    This is a naive workaround, but this removes the second half of the animation of the target shared sortable. Only tested with simple sortables, no nested or multidrag stuff. Since my project deals with just simple drag and drop, I'm okay with losing that animation, since I gain the correct functional dropping over a non-empty sortable.

    let elLastChild = lastChild(el, options.draggable); 
    
    if(rootEl !== el) {
    	elLastChild = null
    }

    Here's a demo, it and test under Shared list section, it has three instead of two

  2. waynevanson commented on Aug 31, 2020

    @waynevanson
    Contributor

    @aquaductape Thanks for checking out the source!

    If you can make a PR, we can test it on the site to see if any of the tests and examples break in functionality.

  3. jjeff commented on Nov 1, 2020

    @jjeff

    Is this the same bug as #1942?

  4. owen-m1 commented on Jul 4, 2021

    @owen-m1
    Member

    Fixed in 1.14.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions