@salesforcedevs/dx-components 0.43.3-tree-selected-scroll-8 → 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
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import { LightningElement } from "lwc";
|
|
2
|
-
import debounce from "debounce";
|
|
3
2
|
|
|
4
3
|
export const HEIGHT_OF_SIDEBAR_ITEM = 32;
|
|
5
4
|
export const WAIT_TIME_BEFORE_SCROLL_IN_MS = 500;
|
|
6
5
|
|
|
7
6
|
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
|
-
|
|
16
7
|
_sidebarContent: HTMLElement | null = null;
|
|
17
8
|
|
|
9
|
+
selectedElement: HTMLElement | null = null;
|
|
18
10
|
timerId: ReturnType<typeof setTimeout> | null = null;
|
|
19
11
|
|
|
20
12
|
get sidebarContent() {
|
|
@@ -26,31 +18,48 @@ export class SidebarBase extends LightningElement {
|
|
|
26
18
|
return this._sidebarContent;
|
|
27
19
|
}
|
|
28
20
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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);
|
|
46
38
|
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
renderedCallbackWithTimeout = () => {
|
|
42
|
+
this.scrollToSelectedItem();
|
|
47
43
|
};
|
|
48
44
|
|
|
49
45
|
private onSelectedItemRendered = (event: CustomEvent) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this._onSelectedItemRendered.bind(this)(event),
|
|
53
|
-
WAIT_TIME_BEFORE_SCROLL_IN_MS
|
|
54
|
-
);
|
|
46
|
+
event.stopPropagation();
|
|
47
|
+
this.selectedElement = event.detail.element;
|
|
55
48
|
};
|
|
49
|
+
|
|
50
|
+
/*Scroll to selected tree item */
|
|
51
|
+
private scrollToSelectedItem() {
|
|
52
|
+
if (this.selectedElement && this.sidebarContent) {
|
|
53
|
+
const scrollHeight: number =
|
|
54
|
+
this.selectedElement.getBoundingClientRect().bottom -
|
|
55
|
+
this.sidebarContent.getBoundingClientRect().bottom + // We need to remove parent bottom
|
|
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
|
|
58
|
+
this.sidebarContent.scrollTo({
|
|
59
|
+
top: scrollHeight,
|
|
60
|
+
behavior: "smooth"
|
|
61
|
+
});
|
|
62
|
+
this.selectedElement = null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
56
65
|
}
|
|
@@ -145,6 +145,7 @@ export default class Sidebar extends SidebarBase {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
renderedCallback() {
|
|
148
|
+
super.renderedCallback()
|
|
148
149
|
this.initializeSearchScrollPosition();
|
|
149
150
|
}
|
|
150
151
|
|
|
@@ -159,6 +160,7 @@ export default class Sidebar extends SidebarBase {
|
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
disconnectedCallback() {
|
|
163
|
+
super.disconnectedCallback()
|
|
162
164
|
this.matchMedia.removeEventListener("change", this.onMediaChange);
|
|
163
165
|
}
|
|
164
166
|
|
|
@@ -81,7 +81,12 @@ export default class Sidebar extends SidebarBase {
|
|
|
81
81
|
this.matchMedia.addEventListener("change", this.onMediaChange);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
renderedCallback() {
|
|
85
|
+
super.renderedCallback();
|
|
86
|
+
}
|
|
87
|
+
|
|
84
88
|
disconnectedCallback() {
|
|
89
|
+
super.disconnectedCallback()
|
|
85
90
|
this.matchMedia.removeEventListener("change", this.onMediaChange);
|
|
86
91
|
}
|
|
87
92
|
|