Skip to content

Commit 1188730

Browse files
committed
fix(scrollView): ensure scroll element exists for event listeners
Related #6104
1 parent f049521 commit 1188730

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/util/scroll-view.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,20 @@ export class ScrollView {
132132
this._cb = onScrollCallback;
133133
this._pos = [];
134134

135-
this._el.addEventListener('touchstart', this._start.bind(this));
136-
this._el.addEventListener('touchmove', this._move.bind(this));
137-
this._el.addEventListener('touchend', this._end.bind(this));
138-
139-
this._el.parentElement.classList.add('js-scroll');
135+
if (this._el) {
136+
this._el.addEventListener('touchstart', this._start.bind(this));
137+
this._el.addEventListener('touchmove', this._move.bind(this));
138+
this._el.addEventListener('touchend', this._end.bind(this));
139+
this._el.parentElement.classList.add('js-scroll');
140+
}
140141

141142
return () => {
142-
this._el.removeEventListener('touchstart', this._start.bind(this));
143-
this._el.removeEventListener('touchmove', this._move.bind(this));
144-
this._el.removeEventListener('touchend', this._end.bind(this));
145-
146-
this._el.parentElement.classList.remove('js-scroll');
143+
if (this._el) {
144+
this._el.removeEventListener('touchstart', this._start.bind(this));
145+
this._el.removeEventListener('touchmove', this._move.bind(this));
146+
this._el.removeEventListener('touchend', this._end.bind(this));
147+
this._el.parentElement.classList.remove('js-scroll');
148+
}
147149
};
148150
}
149151

0 commit comments

Comments
 (0)