Jexordexan / vue-slicksort

A set of vue mixins to turn any list into an animated, touch-friendly, sortable list ✌️
http://vue-slicksort.netlify.app
Other
1.48k stars 157 forks source link

Cursor style doesn't apply to helper element #115

Closed benj2240 closed 3 years ago

benj2240 commented 4 years ago

Goal

Render cursor as grabbing when dragging an item

Approach

Add helperClass="moving" to the SlickList, and target it with

.moving {
  cursor: grabbing;
}

Problem

The cursor: grabbing; style does not appear to apply. However, the targeting is definitely working; other styles (such as background-color) do apply to the helper.

Cause

The helper element has an inline style: pointer-events: none;. It is applied here: https://github.com/Jexordexan/vue-slicksort/blob/f7d3016062596d46dfa35bf4be75509c4478fbdc/src/ContainerMixin.js#L256 When pointer events are disabled, browsers seem to ignore cursor CSS.

Workaround

The choice to set pointerEvents to none was deliberate; without it we get undesirable behavior. Since the helper is created at the bottom of the the <body>, if pointer events are enabled, as soon as the helper moves, all text below the list is highlighted. Additionally, as the helper moves, other elements of the list are highlighted. So we need a three step approach:

  1. Add pointer-events: auto !important; to the helper styling
  2. Prevent text below the list from being selected by specifying appendTo on the SlickList. I set it to append to the list itself.
  3. Prevent text within the list from being selected by adding user-select: none; to each list item.

Fix

I don't have a recommended fix, and I don't believe one exists. Setting user-select:none; may be undesirable for some users. Setting the default appendTo as the list itself may be undesirable, and would be a breaking change to boot. Setting pointer-events: auto; would definitely be a breaking change.

This may be the true issue behind issue #27 .


Edit: Removed JSFiddle demo links. They were broken by dead unpkg.com URLs, this issue has been close for 2 years, and I doubt they'd have helped anyone regardless.

Jexordexan commented 3 years ago

Your fix could be to apply a moving to the entire body when starting a sort, and then removing the class when the sort ends.