@salesforcedevs/dx-components 0.43.3-tree-selected-scroll-7 → 0.43.3-tree-selected-scroll-8

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": "0.43.3-tree-selected-scroll-7",
3
+ "version": "0.43.3-tree-selected-scroll-8",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -5,6 +5,14 @@ export const HEIGHT_OF_SIDEBAR_ITEM = 32;
5
5
  export const WAIT_TIME_BEFORE_SCROLL_IN_MS = 500;
6
6
 
7
7
  export class SidebarBase extends LightningElement {
8
+
9
+ /**
10
+ * For a sidebar instance it needs to be scrolled only once when user is opening a url with selected item
11
+ * No need to scroll more than once if the event is trigged multiple times because of rerendering of component
12
+ */
13
+
14
+ private isSidebarScrolled = false;
15
+
8
16
  _sidebarContent: HTMLElement | null = null;
9
17
 
10
18
  timerId: ReturnType<typeof setTimeout> | null = null;
@@ -21,17 +29,20 @@ export class SidebarBase extends LightningElement {
21
29
  /*Scroll to selected tree item */
22
30
  private _onSelectedItemRendered = (event: CustomEvent) => {
23
31
  event.stopPropagation();
24
- const selectedElement = event.detail.element;
25
- if (selectedElement && this.sidebarContent) {
26
- const scrollHeight: number =
27
- selectedElement.getBoundingClientRect().bottom -
28
- this.sidebarContent.getBoundingClientRect().bottom + // We need to remove parent bottom
29
- HEIGHT_OF_SIDEBAR_ITEM * 3 + // add height of 3 more items so that user can see at least three more items after selected item
30
- this.sidebarContent.offsetTop; // We need to add sidebar offsetTop value as scrollTo will consider it
31
- this.sidebarContent.scrollTo({
32
- top: scrollHeight,
33
- behavior: "smooth"
34
- });
32
+ if (!this.isSidebarScrolled) {
33
+ const selectedElement = event.detail.element;
34
+ if (selectedElement && this.sidebarContent) {
35
+ const scrollHeight: number =
36
+ selectedElement.getBoundingClientRect().bottom -
37
+ this.sidebarContent.getBoundingClientRect().bottom + // We need to remove parent bottom
38
+ HEIGHT_OF_SIDEBAR_ITEM * 3 + // add height of 3 more items so that user can see at least three more items after selected item
39
+ this.sidebarContent.offsetTop; // We need to add sidebar offsetTop value as scrollTo will consider it
40
+ this.sidebarContent.scrollTo({
41
+ top: scrollHeight,
42
+ behavior: "smooth"
43
+ });
44
+ this.isSidebarScrolled = true;
45
+ }
35
46
  }
36
47
  };
37
48