Skip to content

Commit 5fb1b4e

Browse files
DeepAnchorafc163
andauthored
fix: check null ref before removeEventListener (#176)
* fix: check null ref before removeEventListener Fixes error "Cannot read property removeEventListener of null" Related issues: #163 ant-design/ant-design#34816 * Update src/ScrollBar.tsx * Update src/ScrollBar.tsx Co-authored-by: afc163 <[email protected]>
1 parent 00915b4 commit 5fb1b4e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/ScrollBar.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,13 @@ export default class ScrollBar extends React.Component<ScrollBarProps, ScrollBar
8989
window.removeEventListener('mousemove', this.onMouseMove);
9090
window.removeEventListener('mouseup', this.onMouseUp);
9191

92-
this.scrollbarRef.current.removeEventListener('touchstart', this.onScrollbarTouchStart);
93-
this.thumbRef.current.removeEventListener('touchstart', this.onMouseDown);
94-
this.thumbRef.current.removeEventListener('touchmove', this.onMouseMove);
95-
this.thumbRef.current.removeEventListener('touchend', this.onMouseUp);
92+
this.scrollbarRef.current?.removeEventListener('touchstart', this.onScrollbarTouchStart);
93+
94+
if (this.thumbRef.current) {
95+
this.thumbRef.current.removeEventListener('touchstart', this.onMouseDown);
96+
this.thumbRef.current.removeEventListener('touchmove', this.onMouseMove);
97+
this.thumbRef.current.removeEventListener('touchend', this.onMouseUp);
98+
}
9699

97100
raf.cancel(this.moveRaf);
98101
};

0 commit comments

Comments
 (0)