@salesforcedevs/dx-components 1.37.0 → 1.37.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "1.37.0",
3
+ "version": "1.37.1",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -44,5 +44,5 @@
44
44
  "luxon": "3.4.4",
45
45
  "msw": "^2.12.4"
46
46
  },
47
- "gitHead": "9c95fcffb4aaa1cf71a06334fc3b854b39c8a5b0"
47
+ "gitHead": "0425dec453ebb79ed0041e1c8ea18fccf893d425"
48
48
  }
@@ -5,6 +5,7 @@ import { track } from "dxUtils/analytics";
5
5
  const RESTORE_SCROLL_EVENT_NAME = "restore-scroll";
6
6
  const SCROLL_EVENT_NAME = "scroll";
7
7
  const GLOBAL_NAV_TOGGLE_EVENT_NAME = "toggle_global_nav";
8
+ const FULLSCREEN_CHANGE_EVENT_NAME = "fullscreenchange";
8
9
 
9
10
  const LOAD_TIME_SCROLL_RESTORE_DELAY = 750;
10
11
  const REDUNDANT_INSTANCE_ERROR_MESSAGE =
@@ -55,6 +56,7 @@ export default class ScrollManager extends LightningElement {
55
56
  private scrolledSevenFivePercent = false;
56
57
  private scrolledOneHundredPercent = false;
57
58
  private scrollUnlocked = false;
59
+ private lastKnownScrollTop = 0;
58
60
 
59
61
  renderedCallback() {
60
62
  scrollUnlocked = window.location.hash !== ""; // if we have anchor links, skip the entire scroll restore
@@ -105,15 +107,39 @@ export default class ScrollManager extends LightningElement {
105
107
  GLOBAL_NAV_TOGGLE_EVENT_NAME,
106
108
  this.onGlobalNavToggle
107
109
  );
110
+ document.addEventListener(
111
+ FULLSCREEN_CHANGE_EVENT_NAME,
112
+ this.onFullscreenChange
113
+ );
108
114
  } else {
109
115
  console.error(REDUNDANT_INSTANCE_ERROR_MESSAGE);
110
116
  }
111
117
  }
112
118
 
113
119
  onWindowScroll = () => {
120
+ if (!document.fullscreenElement) {
121
+ this.lastKnownScrollTop = (
122
+ document.scrollingElement || document.body
123
+ ).scrollTop;
124
+ }
114
125
  this.updateScrollState();
115
126
  };
116
127
 
128
+ /*
129
+ Preserve the last valid scroll position, as fullscreen temporarily resets it to 0.
130
+ Used to restore the original position on exit.
131
+ */
132
+ onFullscreenChange = () => {
133
+ const isExitingFullscreen = !document.fullscreenElement;
134
+ if (isExitingFullscreen && this.lastKnownScrollTop > 0) {
135
+ const target = this.lastKnownScrollTop;
136
+ requestAnimationFrame(() => {
137
+ document.body.scrollTop = document.documentElement.scrollTop =
138
+ target;
139
+ });
140
+ }
141
+ };
142
+
117
143
  onGlobalNavToggle = (event: Event) => {
118
144
  const isGlobalNavShowing: boolean = (event as CustomEvent).detail;
119
145
  HTML_ELEMENT?.setAttribute(
@@ -208,5 +234,9 @@ export default class ScrollManager extends LightningElement {
208
234
  GLOBAL_NAV_TOGGLE_EVENT_NAME,
209
235
  this.onGlobalNavToggle
210
236
  );
237
+ document.removeEventListener(
238
+ FULLSCREEN_CHANGE_EVENT_NAME,
239
+ this.onFullscreenChange
240
+ );
211
241
  }
212
242
  }