SortableJS / Sortable

Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
https://sortablejs.github.io/Sortable/
MIT License
29.59k stars 3.7k forks source link

[Wishlish] Disable deselection of elements #1612

Open ikegami opened 5 years ago

ikegami commented 5 years ago

Hi! Could you please add an option to the MultiDrag plugin that disables deselecting of objects (i.e. avoids calling _deselectMultiDrag). It would be nice to have buttons that interact with the selected objects.

owen-m1 commented 5 years ago

Perhaps there can be a deselectZone HTMLElement option that, if clicked, will deselect all elements in that sortable.

ikegami commented 5 years ago

Perhaps there can be a deselectZone HTMLElement option that, if clicked, will deselect all elements in that sortable.

I'm not sure how that pertains to what I suggested?

Note that what you suggest is already trivially easy to produce:

$button.click(
   (evt) => {
      $('> .sortable-selected', $sortable).each(
         (i, child) => {
            Sortable.utils.deselect(child);
         }
   )
);
ikegami commented 5 years ago

Right now, I'm using the following hack to achieve the requested enhancement:

// Prevent deselection on external click.
// HACK
let deselectMultiDrag = sortable.multiDrag._deselectMultiDrag;
document.removeEventListener('pointerup', deselectMultiDrag, false);
document.removeEventListener('mouseup',   deselectMultiDrag, false);
document.removeEventListener('touchend',  deselectMultiDrag, false);
owen-m1 commented 5 years ago

@ikegami It does pertain to what you suggest because the deselectZone option would be the document by default, and then when it is changed to another element, the multi drag elements would only get deselected when that element is clicked (as opposed to clicking anywhere on the document).

ikegami commented 5 years ago

ah, I see what you mean. That would indeed be a suitable interface.

aurovrata commented 5 years ago

has this deselectZone been implemented?

Another possible solution would be to add a class such as multidrag-click-ignore (or a data- attribute) to elements within the document that ought to be ignored when a click even is registered coming from them.

aurovrata commented 5 years ago

my current solution to this issue is to stop the event propagation on the specific element I wish to interact with without deselecting the items,

$(element).on('pointerup mouseup touchend', function(event){
  event.stopPropagation();
});
BrianKan714 commented 5 years ago

But it seems it still cannot stop deselection while clicking on scrollBar Is it possible to make the feature of deselecting option while clicking empty space as one of config options. If true, deselect the multi drag option, otherwise no reaction,

aurovrata commented 5 years ago

likely you are not catching the event on the right element. You'll need to inspect your scroll bar and check which element is firing the event. It is possible there are more than one. You could bind an event callback on the document itself to see where your event is coming from.