Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Sortable swapping does not work when forceFallback is enabled and a handle or content is a custom element (web component) with a shadowRoot #2346

Closed
driskull opened this issue Feb 14, 2024 · 5 comments

Comments

@driskull
Copy link
Contributor

driskull commented Feb 14, 2024

Describe the bug

  • When in forceFallback: true, and the handle or list content is a web component with an open shadowRoot items cannot be dragged.
  • In our usage, our handle element is another custom element with shadowRoot and the content within a sortable element is also a custom element.
  • The code problem area is seen in this section:

    Sortable/src/Sortable.js

    Lines 756 to 759 in 07708fa

    while (target && target.shadowRoot) {
    target = target.shadowRoot.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
    if (target === parent) break;
    parent = target;
  • With this line target = target.shadowRoot.elementFromPoint(touchEvt.clientX, touchEvt.clientY);, its returning elements within our handle custom element or content custom element instead of a child of the Sortable instance.
  • This only happens when in forceFallback: true or when used by a mobile device which seems to always go into fallback mode.
  • When using native drag and drop the issue is not seen.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codepen.io/driskull/pen/OJqrzVL?editors=1010
  2. Try to drag a handle over another handle and notice it won't swap elements
  3. Drag a handle over a list element textContent and notice it does swap
  4. If there are other custom-elements inside the list-element in place of the text content elements won't swap either.
  5. See sample: https://codepen.io/driskull/pen/xxBmpra?editors=0110

Expected behavior

I would expect sort swapping to work when a handle or content within a list is a custom element.

Information

sortablejs = ^1.15.1
@types/sortablejs = ^1.15.1

Additional context
I have a PR open to fix this but need verification that it is the best approach to fixing the issue.

Reproduction
codesandbox: https://codepen.io/driskull/pen/OJqrzVL?editors=1010 and https://codepen.io/driskull/pen/xxBmpra?editors=0110

Pull Request Fix

#2347

driskull added a commit to driskull/Sortable-shadow-host-fix that referenced this issue Feb 14, 2024
driskull added a commit to Esri/calcite-design-system that referenced this issue Feb 15, 2024
**Related Issue:** #8728

## Summary

- Fixes dragging when on a mobile device.
- Sortablejs uses fallback code instead of native drag and drop on
mobile devices.
- Patches `sortablejs` dependency until the fix for the issue is
installed and released.
SortableJS/Sortable#2346
- Adds and uses the dependency `patch-package` to handle patching the
dependency.
- Applies the changes listed here:
SortableJS/Sortable#2347

---------

Co-authored-by: JC Franco <jfranco@esri.com>
Elijbet pushed a commit to Esri/calcite-design-system that referenced this issue Feb 15, 2024
**Related Issue:** #8728

## Summary

- Fixes dragging when on a mobile device.
- Sortablejs uses fallback code instead of native drag and drop on
mobile devices.
- Patches `sortablejs` dependency until the fix for the issue is
installed and released.
SortableJS/Sortable#2346
- Adds and uses the dependency `patch-package` to handle patching the
dependency.
- Applies the changes listed here:
SortableJS/Sortable#2347

---------

Co-authored-by: JC Franco <jfranco@esri.com>
@owen-m1
Copy link
Member

owen-m1 commented Mar 22, 2024

Thank you, PR has been merged

@owen-m1 owen-m1 closed this as completed Mar 22, 2024
@driskull
Copy link
Contributor Author

Thank you @owen-m1 🍻

@jcfranco
Copy link

jcfranco commented Apr 5, 2024

Thanks, @driskull and @owen-m1! When is the next SortableJS release planned?

@driskull
Copy link
Contributor Author

@owen-m1 any chance we can get a new release with this fix?

driskull added a commit to Esri/calcite-design-system that referenced this issue Jun 21, 2024
**Related Issue:** #9521

## Summary

- patch sortablejs with the correct update to fix dragging shadow
elements on mobile devices
- SortableJS/Sortable#2347
SortableJS/Sortable#2346
@owen-m1
Copy link
Member

owen-m1 commented Sep 1, 2024

Thank you @driskull it has been released in 1.15.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants