Skip to content

fix(cdk/drag-drop): avoid retaining disabled handles after they've been destroyed #21015

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -344,6 +344,18 @@ export class DragRef<T = any> {
this._handles = handles.map(handle => coerceElement(handle));
this._handles.forEach(handle => toggleNativeDragInteractions(handle, false));
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