@salesforcedevs/dx-components 0.43.3-tree-selected-scroll-3 → 0.43.3-tree-selected-scroll-6

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-3",
3
+ "version": "0.43.3-tree-selected-scroll-6",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -1,11 +1,13 @@
1
1
  import { LightningElement } from "lwc";
2
2
 
3
3
  export const HEIGHT_OF_SIDEBAR_ITEM = 32;
4
+ export const WAIT_TIME_BEFORE_SCROLL_IN_MS = 500;
4
5
 
5
6
  export class SidebarBase extends LightningElement {
6
7
  _sidebarContent: HTMLElement | null = null;
7
- private selectedTreeItem: HTMLElement | null = null;
8
- private isSidebarRendered = false;
8
+ selectedTreeItem: HTMLElement | null = null;
9
+
10
+ timerId: ReturnType<typeof setTimeout> | null = null;
9
11
 
10
12
  get sidebarContent() {
11
13
  if (!this._sidebarContent) {
@@ -19,13 +21,10 @@ export class SidebarBase extends LightningElement {
19
21
  private onSelectedItemRendered(event: CustomEvent) {
20
22
  event.stopPropagation();
21
23
  this.selectedTreeItem = event.detail.element;
22
- if (this.isSidebarRendered) {
23
- this.scrollToSelectedItem();
24
- }
25
24
  }
26
25
 
27
26
  /*Scroll to selected tree item */
28
- private scrollToSelectedItem(): void {
27
+ private scrollToSelectedTreeItem() {
29
28
  if (this.selectedTreeItem && this.sidebarContent) {
30
29
  const scrollHeight: number =
31
30
  this.selectedTreeItem.getBoundingClientRect().bottom -
@@ -35,12 +34,18 @@ export class SidebarBase extends LightningElement {
35
34
  top: scrollHeight,
36
35
  behavior: "smooth"
37
36
  });
37
+ this.selectedTreeItem = null;
38
38
  }
39
- this.selectedTreeItem = null;
40
39
  }
41
40
 
42
41
  renderedCallback(): void {
43
- this.isSidebarRendered = true;
44
- this.scrollToSelectedItem();
42
+ // Implementing debouncing kind of logic here, So that multiple scrolls won't be triggered during multiple renders of selected item
43
+ if (this.timerId) {
44
+ clearTimeout(this.timerId);
45
+ }
46
+ this.timerId = setTimeout(
47
+ () => this.scrollToSelectedTreeItem(),
48
+ WAIT_TIME_BEFORE_SCROLL_IN_MS
49
+ );
45
50
  }
46
51
  }