Skip to content

Commit 7ab8a8e

Browse files
crisbetowagnermaciel
authored andcommitted
fix(cdk/drag-drop): avoid retaining disabled handles after they've been 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)
1 parent cb6f053 commit 7ab8a8e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/cdk/drag-drop/drag-ref.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,18 @@ export class DragRef<T = any> {
345345
this._handles = handles.map(handle => coerceElement(handle));
346346
this._handles.forEach(handle => toggleNativeDragInteractions(handle, this.disabled));
347347
this._toggleNativeDragInteractions();
348+
349+
// Delete any lingering disabled handles that may have been destroyed. Note that we re-create
350+
// the set, rather than iterate over it and filter out the destroyed handles, because while
351+
// the ES spec allows for sets to be modified while they're being iterated over, some polyfills
352+
// use an array internally which may throw an error.
353+
const disabledHandles = new Set<HTMLElement>();
354+
this._disabledHandles.forEach(handle => {
355+
if (this._handles.indexOf(handle) > -1) {
356+
disabledHandles.add(handle);
357+
}
358+
});
359+
this._disabledHandles = disabledHandles;
348360
return this;
349361
}
350362

0 commit comments

Comments
 (0)