Skip to content

Commit 584cb62

Browse files
committed
chore(*): Move logic for calculating scroll size to base helper.
1 parent 9ec27ca commit 584cb62

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

projects/igniteui-angular/src/lib/directives/for-of/base.helper.component.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,19 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
5252
public get size() {
5353
return this._size;
5454
}
55+
56+
public get scrollNativeSize() {
57+
const div = document.createElement('div');
58+
const style = div.style;
59+
style.width = '100px';
60+
style.height = '100px';
61+
style.position = 'absolute';
62+
style.top = '-10000px';
63+
style.top = '-10000px';
64+
style.overflow = 'scroll';
65+
document.body.appendChild(div);
66+
const scrollWidth = div.offsetWidth - div.clientWidth;
67+
document.body.removeChild(div);
68+
return scrollWidth ? scrollWidth + 1 : 1;
69+
}
5570
}

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,12 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
709709
return this.sizesCache[index + 1] - this.sizesCache[index];
710710
}
711711

712-
public getScrollbarWidth() {
713-
return this.scrollComponent ? (this.scrollComponent as VirtualHelperComponent).scrollWidth : 0;
712+
/**
713+
* @hidden
714+
* Function that is called to get the native scrollbar size that the browsers renders.
715+
*/
716+
public getScrollNativeSize() {
717+
return this.scrollComponent ? this.scrollComponent.scrollNativeSize : 0;
714718
}
715719

716720
/**

projects/igniteui-angular/src/lib/directives/for-of/virtual.helper.component.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,6 @@ export class VirtualHelperComponent extends VirtualHelperBaseDirective implement
2525
}
2626

2727
ngOnInit() {
28-
this.scrollWidth = this.getScrollWidth();
28+
this.scrollWidth = this.scrollNativeSize;
2929
}
30-
31-
private getScrollWidth() {
32-
const div = document.createElement('div');
33-
const style = div.style;
34-
style.width = '100px';
35-
style.height = '100px';
36-
style.position = 'absolute';
37-
style.top = '-10000px';
38-
style.top = '-10000px';
39-
style.overflow = 'scroll';
40-
document.body.appendChild(div);
41-
const scrollWidth = div.offsetWidth - div.clientWidth;
42-
document.body.removeChild(div);
43-
return scrollWidth ? scrollWidth + 1 : 1;
44-
}
45-
4630
}

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
177177
* @hidden @internal
178178
*/
179179
public get scrollSize() {
180-
return this.verticalScrollContainer.getScrollbarWidth();
180+
return this.verticalScrollContainer.getScrollNativeSize();
181181
}
182182

183183
private _resourceStrings = CurrentResourceStrings.GridResStrings;

0 commit comments

Comments
 (0)