@salesforcedevs/dx-components 0.43.3-tree-selected-scroll-6 → 0.43.3-tree-selected-scroll-9
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
|
@@ -5,8 +5,8 @@ export const WAIT_TIME_BEFORE_SCROLL_IN_MS = 500;
|
|
|
5
5
|
|
|
6
6
|
export class SidebarBase extends LightningElement {
|
|
7
7
|
_sidebarContent: HTMLElement | null = null;
|
|
8
|
-
selectedTreeItem: HTMLElement | null = null;
|
|
9
8
|
|
|
9
|
+
selectedElement: HTMLElement | null = null;
|
|
10
10
|
timerId: ReturnType<typeof setTimeout> | null = null;
|
|
11
11
|
|
|
12
12
|
get sidebarContent() {
|
|
@@ -18,34 +18,48 @@ export class SidebarBase extends LightningElement {
|
|
|
18
18
|
return this._sidebarContent;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
renderedCallback(): void {
|
|
22
|
+
/**
|
|
23
|
+
* Implementing debouncing kind of logic here to scroll to selected element once tree rendering is done
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
if (this.timerId) {
|
|
27
|
+
clearTimeout(this.timerId);
|
|
28
|
+
}
|
|
29
|
+
this.timerId = setTimeout(
|
|
30
|
+
this.renderedCallbackWithTimeout,
|
|
31
|
+
WAIT_TIME_BEFORE_SCROLL_IN_MS
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
disconnectedCallback(): void {
|
|
36
|
+
if (this.timerId) {
|
|
37
|
+
clearTimeout(this.timerId);
|
|
38
|
+
}
|
|
24
39
|
}
|
|
25
40
|
|
|
41
|
+
renderedCallbackWithTimeout = () => {
|
|
42
|
+
this.scrollToSelectedItem();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
private onSelectedItemRendered = (event: CustomEvent) => {
|
|
46
|
+
event.stopPropagation();
|
|
47
|
+
this.selectedElement = event.detail.element;
|
|
48
|
+
};
|
|
49
|
+
|
|
26
50
|
/*Scroll to selected tree item */
|
|
27
|
-
private
|
|
28
|
-
if (this.
|
|
51
|
+
private scrollToSelectedItem() {
|
|
52
|
+
if (this.selectedElement && this.sidebarContent) {
|
|
29
53
|
const scrollHeight: number =
|
|
30
|
-
this.
|
|
54
|
+
this.selectedElement.getBoundingClientRect().bottom -
|
|
31
55
|
this.sidebarContent.getBoundingClientRect().bottom + // We need to remove parent bottom
|
|
32
|
-
HEIGHT_OF_SIDEBAR_ITEM * 3
|
|
56
|
+
HEIGHT_OF_SIDEBAR_ITEM * 3 + // add height of 3 more items so that user can see at least three more items after selected item
|
|
57
|
+
this.sidebarContent.offsetTop; // We need to add sidebar offsetTop value as scrollTo will consider it
|
|
33
58
|
this.sidebarContent.scrollTo({
|
|
34
59
|
top: scrollHeight,
|
|
35
60
|
behavior: "smooth"
|
|
36
61
|
});
|
|
37
|
-
this.
|
|
62
|
+
this.selectedElement = null;
|
|
38
63
|
}
|
|
39
64
|
}
|
|
40
|
-
|
|
41
|
-
renderedCallback(): void {
|
|
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
|
-
);
|
|
50
|
-
}
|
|
51
65
|
}
|
|
@@ -81,11 +81,12 @@ export default class Sidebar extends SidebarBase {
|
|
|
81
81
|
this.matchMedia.addEventListener("change", this.onMediaChange);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
renderedCallback()
|
|
84
|
+
renderedCallback() {
|
|
85
85
|
super.renderedCallback();
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
disconnectedCallback() {
|
|
89
|
+
super.disconnectedCallback()
|
|
89
90
|
this.matchMedia.removeEventListener("change", this.onMediaChange);
|
|
90
91
|
}
|
|
91
92
|
|