Skip to content

Commit

Permalink
fix(list): fix mobile device dragging with nested lists (#9573)
Browse files Browse the repository at this point in the history
**Related Issue:** #9521

## Summary

- Makes sure that `connectSortableComponent` isn't called during an
active drag of a sortable item.
- Previously, mutation observers were calling `connectSortableComponent`
during a drag
- This caused the existing implementation to be destroyed and a new one
created which left the user in a frozen state.
- This only occurred on mobile devices because mobile devices do not use
native drag and drop with Sortable.js
- The fix makes sure that `connectSortableComponent` and
`disconnectSortableComponent` do nothing during an active drag.
  • Loading branch information
driskull committed Jun 17, 2024
1 parent 7117c6b commit 6f466aa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 27 deletions.
9 changes: 0 additions & 9 deletions packages/calcite-components/src/components/list/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
connectSortableComponent,
disconnectSortableComponent,
SortableComponent,
dragActive,
} from "../../utils/sortableComponent";
import { SLOTS as STACK_SLOTS } from "../stack/resources";
import {
Expand Down Expand Up @@ -400,10 +399,6 @@ export class List
//--------------------------------------------------------------------------

connectedCallback(): void {
if (dragActive(this)) {
return;
}

connectLocalized(this);
connectMessages(this);
this.connectObserver();
Expand All @@ -427,10 +422,6 @@ export class List
}

disconnectedCallback(): void {
if (dragActive(this)) {
return;
}

this.disconnectObserver();
disconnectSortableComponent(this);
disconnectInteractive(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
connectSortableComponent,
disconnectSortableComponent,
SortableComponent,
dragActive,
} from "../../utils/sortableComponent";
import { focusElement } from "../../utils/dom";
import { CSS } from "./resources";
Expand Down Expand Up @@ -102,20 +101,12 @@ export class SortableList implements InteractiveComponent, SortableComponent {
// --------------------------------------------------------------------------

connectedCallback(): void {
if (dragActive(this)) {
return;
}

this.setUpSorting();
this.beginObserving();
connectInteractive(this);
}

disconnectedCallback(): void {
if (dragActive(this)) {
return;
}

disconnectInteractive(this);
disconnectSortableComponent(this);
this.endObserving();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import {
connectSortableComponent,
disconnectSortableComponent,
SortableComponent,
dragActive,
} from "../../utils/sortableComponent";
import { focusElement } from "../../utils/dom";
import { ValueListMessages } from "./assets/value-list/t9n";
Expand Down Expand Up @@ -240,10 +239,6 @@ export class ValueList<
// --------------------------------------------------------------------------

connectedCallback(): void {
if (dragActive(this)) {
return;
}

connectInteractive(this);
connectLocalized(this);
connectMessages(this);
Expand All @@ -267,10 +262,6 @@ export class ValueList<
}

disconnectedCallback(): void {
if (dragActive(this)) {
return;
}

disconnectInteractive(this);
disconnectSortableComponent(this);
disconnectLocalized(this);
Expand Down
8 changes: 8 additions & 0 deletions packages/calcite-components/src/utils/sortableComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export interface SortableComponentItem {
* @param {SortableComponent} component - The sortable component.
*/
export function connectSortableComponent(component: SortableComponent): void {
if (dragActive(component)) {
return;
}

disconnectSortableComponent(component);
sortableComponentSet.add(component);

Expand Down Expand Up @@ -152,6 +156,10 @@ export function connectSortableComponent(component: SortableComponent): void {
* @param {SortableComponent} component - The sortable component.
*/
export function disconnectSortableComponent(component: SortableComponent): void {
if (dragActive(component)) {
return;
}

sortableComponentSet.delete(component);

component.sortable?.destroy();
Expand Down

0 comments on commit 6f466aa

Please sign in to comment.