@salesforcedevs/dx-components 0.43.3-tree-selected-scroll → 0.43.3-tree-selected-scroll-2
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 +1 -1
- package/src/modules/base-elements/sidebarBase/sidebarBase.ts +25 -0
- package/src/modules/dx/sidebar/sidebar.html +1 -0
- package/src/modules/dx/sidebar/sidebar.ts +3 -2
- package/src/modules/dx/sidebarOld/sidebarOld.html +2 -1
- package/src/modules/dx/sidebarOld/sidebarOld.ts +3 -2
- package/src/modules/dx/treeItem/treeItem.css +0 -5
- package/src/modules/dx/treeItem/treeItem.ts +10 -8
- package/src/modules/utils/browser/browser.ts +19 -0
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { LightningElement } from "lwc";
|
|
2
|
+
|
|
3
|
+
const HEIGHT_OF_SIDEBAR_ITEM = 32;
|
|
4
|
+
|
|
5
|
+
export class SidebarBase extends LightningElement {
|
|
6
|
+
/*Scroll to selected tree item */
|
|
7
|
+
private onSelectedItemRendered(event: CustomEvent) {
|
|
8
|
+
event.preventDefault();
|
|
9
|
+
const selectedTreeItem = event.detail.element;
|
|
10
|
+
if (selectedTreeItem) {
|
|
11
|
+
const sidebarContent = this.template.querySelector(
|
|
12
|
+
".sidebar-content-tree"
|
|
13
|
+
);
|
|
14
|
+
if (sidebarContent) {
|
|
15
|
+
sidebarContent.scrollTo({
|
|
16
|
+
top:
|
|
17
|
+
selectedTreeItem.offsetTop +
|
|
18
|
+
HEIGHT_OF_SIDEBAR_ITEM + // add height of sidebar item
|
|
19
|
+
HEIGHT_OF_SIDEBAR_ITEM * 2, // add height of 2 more items so that user can see at least two more items after selected item
|
|
20
|
+
behavior: "smooth"
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import cx from "classnames";
|
|
2
2
|
import { track as trackAnalytics } from "dx/instrumentation";
|
|
3
|
-
import {
|
|
3
|
+
import { api, track } from "lwc";
|
|
4
4
|
import {
|
|
5
5
|
TreeNode,
|
|
6
6
|
SidebarGtmAction,
|
|
@@ -9,11 +9,12 @@ import {
|
|
|
9
9
|
import { getSidebarSearchParams } from "utils/coveo";
|
|
10
10
|
import { toJson } from "utils/normalizers";
|
|
11
11
|
import SidebarSearch from "dx/sidebarSearch";
|
|
12
|
+
import { SidebarBase } from "base-elements/sidebarBase";
|
|
12
13
|
|
|
13
14
|
const MOBILE_SIZE_MATCH = "768px";
|
|
14
15
|
const TOGGLE_BUTTON_LABEL = "Toggle Sidebar";
|
|
15
16
|
|
|
16
|
-
export default class Sidebar extends
|
|
17
|
+
export default class Sidebar extends SidebarBase {
|
|
17
18
|
@api coveoOrganizationId!: string;
|
|
18
19
|
@api coveoPublicAccessToken!: string;
|
|
19
20
|
@api coveoSearchHub!: string;
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
></dx-input>
|
|
50
50
|
</div>
|
|
51
51
|
</div>
|
|
52
|
-
<div class="sidebar-content" if:true={anyResultMatch}>
|
|
52
|
+
<div class="sidebar-content sidebar-content-tree" if:true={anyResultMatch}>
|
|
53
53
|
<dx-tree
|
|
54
54
|
for:each={filteredTrees}
|
|
55
55
|
for:item="tree"
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
tree-root={tree.tree}
|
|
58
58
|
onselect={onSelect}
|
|
59
59
|
value={value}
|
|
60
|
+
onselecteditemrendered={onSelectedItemRendered}
|
|
60
61
|
></dx-tree>
|
|
61
62
|
</div>
|
|
62
63
|
<dx-empty-state
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import cx from "classnames";
|
|
2
2
|
import { track } from "dx/instrumentation";
|
|
3
|
-
import {
|
|
3
|
+
import { api } from "lwc";
|
|
4
4
|
|
|
5
5
|
import { TreeNode, SidebarGtmAction } from "typings/custom";
|
|
6
6
|
import { toJson } from "utils/normalizers";
|
|
7
|
+
import { SidebarBase } from "base-elements/sidebarBase";
|
|
7
8
|
|
|
8
9
|
const WAIT_TIME = 500;
|
|
9
10
|
const MOBILE_SIZE_MATCH = "768px";
|
|
10
11
|
const TOGGLE_BUTTON_LABEL = "Toggle Sidebar";
|
|
11
12
|
|
|
12
|
-
export default class Sidebar extends
|
|
13
|
+
export default class Sidebar extends SidebarBase {
|
|
13
14
|
@api header: string = "";
|
|
14
15
|
|
|
15
16
|
@api
|
|
@@ -2,6 +2,7 @@ import { LightningElement, api } from "lwc";
|
|
|
2
2
|
import { InternalTreeNode } from "typings/custom";
|
|
3
3
|
import { track } from "dx/instrumentation";
|
|
4
4
|
import { SidebarGtmAction } from "typings/custom";
|
|
5
|
+
import { isInViewport } from "utils/browser";
|
|
5
6
|
|
|
6
7
|
const DEFAULT_TARGET = "_self";
|
|
7
8
|
|
|
@@ -62,18 +63,19 @@ export default class TreeItem extends LightningElement {
|
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
renderedCallback(): void {
|
|
66
|
+
this.sendEventToParentIfSelected();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private sendEventToParentIfSelected(): void {
|
|
65
70
|
/**
|
|
66
|
-
* This is to
|
|
67
|
-
*
|
|
71
|
+
* This is to send selected element reference to parent if it's not visible in the viewport
|
|
72
|
+
* Parent component will use the elements offsetTop scrollTo that element's position
|
|
68
73
|
*/
|
|
69
|
-
|
|
70
74
|
if (this.isSelected) {
|
|
71
75
|
const element = this.template.querySelector("dx-tree-tile");
|
|
72
|
-
if (element) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
inline: "nearest",
|
|
76
|
-
behavior: "smooth"
|
|
76
|
+
if (element && !isInViewport(element)) {
|
|
77
|
+
this.fireEvent("selecteditemrendered", {
|
|
78
|
+
element
|
|
77
79
|
});
|
|
78
80
|
}
|
|
79
81
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns whether given element is in browser viewport or not
|
|
3
|
+
*/
|
|
4
|
+
function isInViewport(element: HTMLElement): boolean {
|
|
5
|
+
if (element) {
|
|
6
|
+
const rect = element.getBoundingClientRect();
|
|
7
|
+
return (
|
|
8
|
+
rect.top >= 0 &&
|
|
9
|
+
rect.left >= 0 &&
|
|
10
|
+
rect.bottom <=
|
|
11
|
+
(window.innerHeight || document.documentElement.clientHeight) &&
|
|
12
|
+
rect.right <=
|
|
13
|
+
(window.innerWidth || document.documentElement.clientWidth)
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { isInViewport };
|