Skip to content

Commit 4e0397e

Browse files
refactor(dashboard): measure scrollbar width directly from element
Replace ScrollbarHelper service with direct offsetWidth - clientWidth measurement on the scrollable element, which is more accurate and SSR-safe. DEPRECATED: `ScrollbarHelper` service is deprecated and will be removed in v51. Use `element.offsetWidth - element.clientWidth` on the scrollable element instead.
1 parent dcf58b1 commit 4e0397e

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

projects/element-ng/common/services/scrollbar-helper.service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import { inject, Injectable, DOCUMENT } from '@angular/core';
77
/**
88
* Gets the width of the scrollbar. Nesc for windows
99
* http://stackoverflow.com/a/13382873/888165
10+
*
11+
* @deprecated This service uses a legacy DOM-measurement hack to determine scrollbar width.
12+
* Use `element.offsetWidth - element.clientWidth` on the scrollable element directly,
13+
* which is more accurate, SSR-safe, and accounts for OS-level theming and CSS overrides.
14+
* Will be removed in v51.
1015
*/
16+
1117
@Injectable({ providedIn: 'root' })
1218
export class ScrollbarHelper {
1319
private document = inject(DOCUMENT);

projects/element-ng/dashboard/si-dashboard.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
viewChild
2222
} from '@angular/core';
2323
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
24-
import { ScrollbarHelper } from '@siemens/element-ng/common';
2524
import {
2625
BOOTSTRAP_BREAKPOINTS,
2726
ElementDimensions,
@@ -99,7 +98,6 @@ export class SiDashboardComponent implements OnChanges, AfterViewInit {
9998
private scroller = inject(ViewportScroller);
10099
private dashboardService = inject(SiDashboardService);
101100
private resizeObserver = inject(ResizeObserverService);
102-
private scrollbarHelper = inject(ScrollbarHelper);
103101
private cdRef = inject(ChangeDetectorRef);
104102
private document = inject(DOCUMENT);
105103
private readonly hideMenubarInternal = signal(false);
@@ -256,7 +254,8 @@ export class SiDashboardComponent implements OnChanges, AfterViewInit {
256254
dashboardFrameDimensions &&
257255
dashboardDimensions.height > dashboardFrameDimensions.height
258256
) {
259-
padding = padding - this.scrollbarHelper.width;
257+
const { offsetWidth, clientWidth } = this.dashboardFrame().nativeElement;
258+
padding = padding - (offsetWidth - clientWidth);
260259
}
261260
this.dashboardFrameEndPadding = padding;
262261
this.cdRef.markForCheck();

0 commit comments

Comments
 (0)