@profitlich/template-toolkit 5.2.1 → 5.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,6 +25,7 @@ export class MenuToggle {
25
25
  #deferPositionFixed;
26
26
  #lockScroll;
27
27
  #fixElement;
28
+ #fixElementIsBody;
28
29
  #y;
29
30
  #bodyClickHandler;
30
31
  #resizeHandler;
@@ -54,6 +55,7 @@ export class MenuToggle {
54
55
  this.#deferPositionFixed = deferPositionFixed;
55
56
  this.#lockScroll = lockScroll;
56
57
  this.#fixElement = fixElementSelector ? document.querySelector(fixElementSelector) : document.body;
58
+ this.#fixElementIsBody = this.#fixElement === document.body;
57
59
  this.#scrollbarWidth = 0;
58
60
  this.isActive = false;
59
61
  this.#y = 0;
@@ -108,7 +110,9 @@ export class MenuToggle {
108
110
  this.#shiftElement.style.marginRight = '';
109
111
  this.#shiftElement.style.width = '';
110
112
  }
111
- this.#fixElement.style.paddingRight = '';
113
+ if (this.#fixElementIsBody) {
114
+ this.#fixElement.style.paddingRight = '';
115
+ }
112
116
  this.#fixElement.style.top = '';
113
117
  window.scrollTo(0, this.#y);
114
118
  }
@@ -143,12 +147,21 @@ export class MenuToggle {
143
147
  document.dispatchEvent(event);
144
148
  }
145
149
 
150
+ // Scrollbar-Ausgleich nur nötig, wenn der Body fixiert wird –
151
+ // bei anderem #fixElement bleibt die Seiten-Scrollbar bestehen.
146
152
  #applyFix() {
147
153
  this.#scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
148
154
  this.#y = window.scrollY;
149
- this.#fixElement.style.paddingRight = `${this.#scrollbarWidth}px`;
155
+ if (this.#fixElementIsBody) {
156
+ this.#fixElement.style.paddingRight = `${this.#scrollbarWidth}px`;
157
+ }
150
158
  this.#fixElement.style.top = `-${this.#y}px`;
151
159
  this.#fixElement.setAttribute('data-menu-fixed', 'true');
160
+ if (!this.#fixElementIsBody) {
161
+ // Bei nicht-body-Fix-Element bleibt der window-Scroll erhalten; ohne Reset
162
+ // erscheint ein absolut positioniertes Menü um den vorherigen Scroll-Betrag verschoben.
163
+ window.scrollTo(0, 0);
164
+ }
152
165
  }
153
166
 
154
167
  #adjustShiftElementWidth() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@profitlich/template-toolkit",
3
- "version": "5.2.1",
3
+ "version": "5.2.3",
4
4
  "description": "Shared SCSS layout system, JS utilities, components and build scripts for profitlich template repos",
5
5
  "type": "module",
6
6
  "sass": "scss/forward.scss",