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

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-4",
3
+ "version": "0.43.3-tree-selected-scroll-7",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -1,9 +1,14 @@
1
1
  import { LightningElement } from "lwc";
2
+ import debounce from "debounce";
2
3
 
3
4
  export const HEIGHT_OF_SIDEBAR_ITEM = 32;
5
+ export const WAIT_TIME_BEFORE_SCROLL_IN_MS = 500;
4
6
 
5
7
  export class SidebarBase extends LightningElement {
6
8
  _sidebarContent: HTMLElement | null = null;
9
+
10
+ timerId: ReturnType<typeof setTimeout> | null = null;
11
+
7
12
  get sidebarContent() {
8
13
  if (!this._sidebarContent) {
9
14
  this._sidebarContent = this.template.querySelector(
@@ -14,18 +19,27 @@ export class SidebarBase extends LightningElement {
14
19
  }
15
20
 
16
21
  /*Scroll to selected tree item */
17
- private onSelectedItemRendered(event: CustomEvent) {
22
+ private _onSelectedItemRendered = (event: CustomEvent) => {
18
23
  event.stopPropagation();
19
- const selectedTreeItem = event.detail.element;
20
- if (selectedTreeItem && this.sidebarContent) {
24
+ const selectedElement = event.detail.element;
25
+ if (selectedElement && this.sidebarContent) {
21
26
  const scrollHeight: number =
22
- selectedTreeItem.getBoundingClientRect().bottom -
27
+ selectedElement.getBoundingClientRect().bottom -
23
28
  this.sidebarContent.getBoundingClientRect().bottom + // We need to remove parent bottom
24
- HEIGHT_OF_SIDEBAR_ITEM * 3; // add height of 3 more items so that user can see at least three more items after selected item
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
25
31
  this.sidebarContent.scrollTo({
26
32
  top: scrollHeight,
27
33
  behavior: "smooth"
28
34
  });
29
35
  }
30
- }
36
+ };
37
+
38
+ private onSelectedItemRendered = (event: CustomEvent) => {
39
+ debounce(
40
+ // @ts-ignore something weird happening here with debounce types
41
+ this._onSelectedItemRendered.bind(this)(event),
42
+ WAIT_TIME_BEFORE_SCROLL_IN_MS
43
+ );
44
+ };
31
45
  }