@salesforcedevs/dx-components 0.43.3-tree-selected-scroll-6 → 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,11 +1,11 @@
|
|
|
1
1
|
import { LightningElement } from "lwc";
|
|
2
|
+
import debounce from "debounce";
|
|
2
3
|
|
|
3
4
|
export const HEIGHT_OF_SIDEBAR_ITEM = 32;
|
|
4
5
|
export const WAIT_TIME_BEFORE_SCROLL_IN_MS = 500;
|
|
5
6
|
|
|
6
7
|
export class SidebarBase extends LightningElement {
|
|
7
8
|
_sidebarContent: HTMLElement | null = null;
|
|
8
|
-
selectedTreeItem: HTMLElement | null = null;
|
|
9
9
|
|
|
10
10
|
timerId: ReturnType<typeof setTimeout> | null = null;
|
|
11
11
|
|
|
@@ -18,34 +18,28 @@ export class SidebarBase extends LightningElement {
|
|
|
18
18
|
return this._sidebarContent;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
private onSelectedItemRendered(event: CustomEvent) {
|
|
22
|
-
event.stopPropagation();
|
|
23
|
-
this.selectedTreeItem = event.detail.element;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
21
|
/*Scroll to selected tree item */
|
|
27
|
-
private
|
|
28
|
-
|
|
22
|
+
private _onSelectedItemRendered = (event: CustomEvent) => {
|
|
23
|
+
event.stopPropagation();
|
|
24
|
+
const selectedElement = event.detail.element;
|
|
25
|
+
if (selectedElement && this.sidebarContent) {
|
|
29
26
|
const scrollHeight: number =
|
|
30
|
-
|
|
27
|
+
selectedElement.getBoundingClientRect().bottom -
|
|
31
28
|
this.sidebarContent.getBoundingClientRect().bottom + // We need to remove parent bottom
|
|
32
|
-
HEIGHT_OF_SIDEBAR_ITEM * 3
|
|
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
|
|
33
31
|
this.sidebarContent.scrollTo({
|
|
34
32
|
top: scrollHeight,
|
|
35
33
|
behavior: "smooth"
|
|
36
34
|
});
|
|
37
|
-
this.selectedTreeItem = null;
|
|
38
35
|
}
|
|
39
|
-
}
|
|
36
|
+
};
|
|
40
37
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
this.timerId = setTimeout(
|
|
47
|
-
() => this.scrollToSelectedTreeItem(),
|
|
38
|
+
private onSelectedItemRendered = (event: CustomEvent) => {
|
|
39
|
+
debounce(
|
|
40
|
+
// @ts-ignore something weird happening here with debounce types
|
|
41
|
+
this._onSelectedItemRendered.bind(this)(event),
|
|
48
42
|
WAIT_TIME_BEFORE_SCROLL_IN_MS
|
|
49
43
|
);
|
|
50
|
-
}
|
|
44
|
+
};
|
|
51
45
|
}
|
|
@@ -81,10 +81,6 @@ export default class Sidebar extends SidebarBase {
|
|
|
81
81
|
this.matchMedia.addEventListener("change", this.onMediaChange);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
renderedCallback(): void {
|
|
85
|
-
super.renderedCallback();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
84
|
disconnectedCallback() {
|
|
89
85
|
this.matchMedia.removeEventListener("change", this.onMediaChange);
|
|
90
86
|
}
|