From f5311dd43bfb0bbc5f8223f2f5431256df5a67e9 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 7 Aug 2024 14:20:08 +0800 Subject: [PATCH] fix(behaviors): fix drag canvas unbind event (#6146) Co-authored-by: antv --- packages/g6/src/behaviors/drag-canvas.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/g6/src/behaviors/drag-canvas.ts b/packages/g6/src/behaviors/drag-canvas.ts index e78572cb39..246197aac0 100644 --- a/packages/g6/src/behaviors/drag-canvas.ts +++ b/packages/g6/src/behaviors/drag-canvas.ts @@ -108,9 +108,10 @@ export class DragCanvas extends BaseBehavior { this.shortcut.bind(left, (event) => this.onTranslate([1, 0], event)); this.shortcut.bind(right, (event) => this.onTranslate([-1, 0], event)); } else { - this.context.graph.on(CanvasEvent.DRAG_START, this.onDragStart); - this.context.graph.on(CanvasEvent.DRAG, this.onDrag); - this.context.graph.on(CanvasEvent.DRAG_END, this.onDragEnd); + const { graph } = this.context; + graph.on(CanvasEvent.DRAG_START, this.onDragStart); + graph.on(CanvasEvent.DRAG, this.onDrag); + graph.on(CanvasEvent.DRAG_END, this.onDragEnd); } } @@ -170,10 +171,10 @@ export class DragCanvas extends BaseBehavior { private unbindEvents() { this.shortcut.unbindAll(); - const canvas = this.canvas; - canvas.removeEventListener(CanvasEvent.DRAG_START, this.onDragStart); - canvas.removeEventListener(CanvasEvent.DRAG, this.onDrag); - canvas.removeEventListener(CanvasEvent.DRAG_END, this.onDragEnd); + const { graph } = this.context; + graph.off(CanvasEvent.DRAG_START, this.onDragStart); + graph.off(CanvasEvent.DRAG, this.onDrag); + graph.off(CanvasEvent.DRAG_END, this.onDragEnd); } public destroy(): void {