Skip to content

Commit

Permalink
fix(cdk/drag-drop): avoid retaining disabled handles after they've be…
Browse files Browse the repository at this point in the history
…en destroyed (#21015)

The `DragRef` keeps track of which of its handles have been disabled, but if one of
them is destroyed, we still keep its reference until the object is destroyed.

These changes add some extra logic to filter them out.

Fixes #21009.

(cherry picked from commit de5a940)
  • Loading branch information
crisbeto authored and wagnermaciel committed Nov 17, 2020
1 parent cb6f053 commit 7ab8a8e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/cdk/drag-drop/drag-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,18 @@ export class DragRef<T = any> {
this._handles = handles.map(handle => coerceElement(handle));
this._handles.forEach(handle => toggleNativeDragInteractions(handle, this.disabled));
this._toggleNativeDragInteractions();

// Delete any lingering disabled handles that may have been destroyed. Note that we re-create
// the set, rather than iterate over it and filter out the destroyed handles, because while
// the ES spec allows for sets to be modified while they're being iterated over, some polyfills
// use an array internally which may throw an error.
const disabledHandles = new Set<HTMLElement>();
this._disabledHandles.forEach(handle => {
if (this._handles.indexOf(handle) > -1) {
disabledHandles.add(handle);
}
});
this._disabledHandles = disabledHandles;
return this;
}

Expand Down

0 comments on commit 7ab8a8e

Please sign in to comment.