Skip to content

Commit 6450938

Browse files
author
Malte Wessel
committed
fixed getter
1 parent 1a37e8f commit 6450938

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/Scrollbars/index.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,38 +95,44 @@ export default class Scrollbars extends Component {
9595
}
9696

9797
getScrollLeft() {
98+
if (!this.view) return 0;
9899
return this.view.scrollLeft;
99100
}
100101

101102
getScrollTop() {
103+
if (!this.view) return 0;
102104
return this.view.scrollTop;
103105
}
104106

105107
getScrollWidth() {
108+
if (!this.view) return 0;
106109
return this.view.scrollWidth;
107110
}
108111

109112
getScrollHeight() {
113+
if (!this.view) return 0;
110114
return this.view.scrollHeight;
111115
}
112116

113117
getClientWidth() {
118+
if (!this.view) return 0;
114119
return this.view.clientWidth;
115120
}
116121

117122
getClientHeight() {
123+
if (!this.view) return 0;
118124
return this.view.clientHeight;
119125
}
120126

121127
getValues() {
122128
const {
123-
scrollLeft,
124-
scrollTop,
125-
scrollWidth,
126-
scrollHeight,
127-
clientWidth,
128-
clientHeight
129-
} = this.view;
129+
scrollLeft = 0,
130+
scrollTop = 0,
131+
scrollWidth = 0,
132+
scrollHeight = 0,
133+
clientWidth = 0,
134+
clientHeight = 0
135+
} = this.view || {};
130136

131137
return {
132138
left: (scrollLeft / (scrollWidth - clientWidth)) || 0,
@@ -175,26 +181,32 @@ export default class Scrollbars extends Component {
175181
}
176182

177183
scrollLeft(left = 0) {
184+
if (!this.view) return;
178185
this.view.scrollLeft = left;
179186
}
180187

181188
scrollTop(top = 0) {
189+
if (!this.view) return;
182190
this.view.scrollTop = top;
183191
}
184192

185193
scrollToLeft() {
194+
if (!this.view) return;
186195
this.view.scrollLeft = 0;
187196
}
188197

189198
scrollToTop() {
199+
if (!this.view) return;
190200
this.view.scrollTop = 0;
191201
}
192202

193203
scrollToRight() {
204+
if (!this.view) return;
194205
this.view.scrollLeft = this.view.scrollWidth;
195206
}
196207

197208
scrollToBottom() {
209+
if (!this.view) return;
198210
this.view.scrollTop = this.view.scrollHeight;
199211
}
200212

0 commit comments

Comments
 (0)