@salesforcedevs/dx-components 1.3.217 → 1.3.218

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.3.217",
3
+ "version": "1.3.218",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -44,5 +44,5 @@
44
44
  "volta": {
45
45
  "node": "16.19.1"
46
46
  },
47
- "gitHead": "97fa28da77d1550d42ebc27eb8878f50fdcac89f"
47
+ "gitHead": "4da04a9390fd75ee83751992b259acb60a47fd98"
48
48
  }
@@ -164,12 +164,13 @@ export default class ScrollManager extends LightningElement {
164
164
  }
165
165
 
166
166
  saveScroll = throttle(100, () => {
167
+ const scrollingElement = document.scrollingElement || document.body;
167
168
  window.history.replaceState(
168
169
  {
169
170
  ...window.history.state,
170
171
  scroll: {
171
- value: document.body.scrollTop,
172
- docSize: document.body.scrollHeight
172
+ value: scrollingElement.scrollTop,
173
+ docSize: scrollingElement.scrollHeight
173
174
  }
174
175
  },
175
176
  "",
@@ -9,6 +9,7 @@ import cx from "classnames";
9
9
  export default class StepSequence extends LightningElement {
10
10
  @api animateTransitions = false;
11
11
  @api communicateStepChanges = false;
12
+ @api containerScrollToId = "";
12
13
  @api forceInitiallyVisible = false;
13
14
  @api initialStepIndex: string | undefined;
14
15
  @api optimizePositionAfterAnimation = false;
@@ -39,15 +40,9 @@ export default class StepSequence extends LightningElement {
39
40
 
40
41
  if (this.useHistory) {
41
42
  this.defaultScrollRestorationValue = history.scrollRestoration;
42
- history.scrollRestoration = "manual";
43
- history.replaceState(
44
- {
45
- ...window.history.state,
46
- currentStepIndex: this.currentStepIndex
47
- },
48
- ""
49
- );
43
+ history.scrollRestoration = "manual"; // Step component must override scroll behavior to work properly with history and maintain scrollTo behavior of component
50
44
  window.addEventListener("popstate", this.handleHistoryPopstate);
45
+ window.addEventListener("hashchange", this.handleHashChange);
51
46
  }
52
47
 
53
48
  if (this.sessionStorageId) {
@@ -87,6 +82,7 @@ export default class StepSequence extends LightningElement {
87
82
 
88
83
  disconnectedCallback() {
89
84
  window.removeEventListener("popstate", this.handleHistoryPopstate);
85
+ window.removeEventListener("hashchange", this.handleHashChange);
90
86
  this.removeEventListener("transitionend", this.handleTransitionEnd);
91
87
  history.scrollRestoration = this.defaultScrollRestorationValue;
92
88
  }
@@ -166,6 +162,17 @@ export default class StepSequence extends LightningElement {
166
162
  }
167
163
 
168
164
  if (this.useHistory && updateHistory) {
165
+ if (typeof history.state?.currentStepIndex !== "number") {
166
+ // This is a "new" interaction with the step component, so we store the current
167
+ // component state in history so that going back from the next step works right
168
+ history.pushState(
169
+ {
170
+ currentStepIndex: this.currentStepIndex
171
+ },
172
+ "",
173
+ this.containerScrollToId // update browser hash for correct "feel" to in-page navigation
174
+ );
175
+ }
169
176
  history.pushState(
170
177
  {
171
178
  currentStepIndex: nextStepIndex
@@ -247,9 +254,34 @@ export default class StepSequence extends LightningElement {
247
254
  }
248
255
 
249
256
  handleHistoryPopstate = ({ state }: PopStateEvent) => {
250
- if (typeof state?.currentStepIndex === "number") {
251
- this.remeasureSteps();
252
- this.changeActiveStep(state.currentStepIndex, false);
257
+ if (
258
+ typeof state?.currentStepIndex !== "number" ||
259
+ state.currentStepIndex === this.currentStepIndex
260
+ ) {
261
+ // This history item is not a step change, so bail early.
262
+ return;
263
+ }
264
+
265
+ this.remeasureSteps();
266
+ this.changeActiveStep(state.currentStepIndex, false);
267
+ this.scrollToStepTop();
268
+ };
269
+
270
+ handleHashChange = ({ newURL }: HashChangeEvent) => {
271
+ const newHash = new URL(newURL).hash;
272
+ const oldScrollValue = history.state?.scroll?.value;
273
+
274
+ if (typeof oldScrollValue === "number") {
275
+ window.scrollTo({
276
+ top: oldScrollValue
277
+ });
278
+ } else if (newHash) {
279
+ document.querySelector(newHash)?.scrollIntoView();
280
+ } else {
281
+ // No hash and no old scroll value means this was the initial history item
282
+ window.scrollTo({
283
+ top: 0
284
+ });
253
285
  }
254
286
  };
255
287