@salesforcedevs/dx-components 0.43.3-tree-selected-scroll-5 → 0.43.3-tree-selected-scroll-8
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,19 @@
|
|
|
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 {
|
|
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
|
+
|
|
7
16
|
_sidebarContent: HTMLElement | null = null;
|
|
8
|
-
selectedTreeItem: HTMLElement | null = null;
|
|
9
17
|
|
|
10
18
|
timerId: ReturnType<typeof setTimeout> | null = null;
|
|
11
19
|
|
|
@@ -18,32 +26,31 @@ export class SidebarBase extends LightningElement {
|
|
|
18
26
|
return this._sidebarContent;
|
|
19
27
|
}
|
|
20
28
|
|
|
21
|
-
|
|
29
|
+
/*Scroll to selected tree item */
|
|
30
|
+
private _onSelectedItemRendered = (event: CustomEvent) => {
|
|
22
31
|
event.stopPropagation();
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
if (!this.isSidebarScrolled) {
|
|
33
|
+
const selectedElement = event.detail.element;
|
|
34
|
+
if (selectedElement && this.sidebarContent) {
|
|
35
|
+
const scrollHeight: number =
|
|
36
|
+
selectedElement.getBoundingClientRect().bottom -
|
|
37
|
+
this.sidebarContent.getBoundingClientRect().bottom + // We need to remove parent bottom
|
|
38
|
+
HEIGHT_OF_SIDEBAR_ITEM * 3 + // add height of 3 more items so that user can see at least three more items after selected item
|
|
39
|
+
this.sidebarContent.offsetTop; // We need to add sidebar offsetTop value as scrollTo will consider it
|
|
40
|
+
this.sidebarContent.scrollTo({
|
|
41
|
+
top: scrollHeight,
|
|
42
|
+
behavior: "smooth"
|
|
43
|
+
});
|
|
44
|
+
this.isSidebarScrolled = true;
|
|
45
|
+
}
|
|
29
46
|
}
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
private onSelectedItemRendered = (event: CustomEvent) => {
|
|
50
|
+
debounce(
|
|
51
|
+
// @ts-ignore something weird happening here with debounce types
|
|
52
|
+
this._onSelectedItemRendered.bind(this)(event),
|
|
32
53
|
WAIT_TIME_BEFORE_SCROLL_IN_MS
|
|
33
54
|
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/*Scroll to selected tree item */
|
|
37
|
-
private scrollToSelectedTreeItem() {
|
|
38
|
-
if (this.selectedTreeItem && this.sidebarContent) {
|
|
39
|
-
const scrollHeight: number =
|
|
40
|
-
this.selectedTreeItem.getBoundingClientRect().bottom -
|
|
41
|
-
this.sidebarContent.getBoundingClientRect().bottom + // We need to remove parent bottom
|
|
42
|
-
HEIGHT_OF_SIDEBAR_ITEM * 3; // add height of 3 more items so that user can see at least three more items after selected item
|
|
43
|
-
this.sidebarContent.scrollTo({
|
|
44
|
-
top: scrollHeight,
|
|
45
|
-
behavior: "smooth"
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
55
|
+
};
|
|
49
56
|
}
|