@salesforcedevs/dx-components 0.9.0 → 0.10.0

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -29,5 +29,5 @@
29
29
  "@types/debounce": "^1.2.0",
30
30
  "@types/lodash.get": "^4.4.6"
31
31
  },
32
- "gitHead": "f2d227d9714d14c900770cc965a152be684aeb56"
32
+ "gitHead": "f91a2edc71e7a19cbc26ccfd6396637d3a706f56"
33
33
  }
@@ -29,18 +29,10 @@ describe(TAG, () => {
29
29
  });
30
30
 
31
31
  const link = component.shadowRoot.querySelector("a");
32
- expect(link).toBeNull();
33
-
34
- const button: HTMLElement = component.shadowRoot.querySelector(
35
- "button"
36
- );
37
- expect(button).not.toBeNull();
38
- expect(button.getAttribute("aria-label")).toBe(
39
- NODE_WITH_CHILDREN.label
40
- );
32
+ expect(link).not.toBeNull();
41
33
 
42
34
  const tile: TreeTile = component.shadowRoot.querySelector(
43
- "button > dx-tree-tile"
35
+ "a > dx-tree-tile"
44
36
  );
45
37
  expect(tile).not.toBeNull();
46
38
  assertTile(tile, {
@@ -66,7 +58,7 @@ describe(TAG, () => {
66
58
  });
67
59
 
68
60
  const tile: TreeTile = component.shadowRoot.querySelector(
69
- "button > dx-tree-tile"
61
+ "a > dx-tree-tile"
70
62
  );
71
63
  expect(tile).not.toBeNull();
72
64
  assertTile(tile, {
@@ -280,14 +272,12 @@ describe(TAG, () => {
280
272
  component.addEventListener("tileselected", mockTileSelected);
281
273
  component.addEventListener("expandcollapse", mockExpandCollapse);
282
274
 
283
- const button: HTMLElement = component.shadowRoot.querySelector(
284
- "button"
285
- );
286
- expect(button).not.toBeNull();
287
- button.click();
275
+ const link: HTMLElement = component.shadowRoot.querySelector("a");
276
+ expect(link).not.toBeNull();
277
+ link.click();
288
278
 
289
279
  expect(track).toBeCalledTimes(1);
290
- expect(track).toBeCalledWith(button, GTM_EVENT_NAME, {
280
+ expect(track).toBeCalledWith(link, GTM_EVENT_NAME, {
291
281
  clickText: NODE_WITH_CHILDREN.label,
292
282
  sideNavAction: "click"
293
283
  });
@@ -328,11 +318,9 @@ describe(TAG, () => {
328
318
  );
329
319
  expect(tile).toHaveProperty("isSelected", true);
330
320
 
331
- const button: HTMLElement = component.shadowRoot.querySelector(
332
- "button"
333
- );
334
- expect(button).not.toBeNull();
335
- button.click();
321
+ const link: HTMLElement = component.shadowRoot.querySelector("a");
322
+ expect(link).not.toBeNull();
323
+ link.click();
336
324
 
337
325
  return Promise.resolve().then(() => {
338
326
  expect(tile).toHaveProperty("isSelected", true);
@@ -1,16 +1,7 @@
1
1
  <template>
2
- <button if:false={href} onclick={onButtonClick} aria-label={treeNode.label}>
3
- <dx-tree-tile
4
- is-root={isRoot}
5
- tree-node={treeNode}
6
- is-expanded={isExpanded}
7
- has-children={hasChildren}
8
- is-selected={isSelected}
9
- oniconclick={onIconClick}
10
- ></dx-tree-tile>
11
- </button>
12
- <a if:true={href} href={href} target={target} onclick={onLinkClick}>
2
+ <a href={href} target={target} onclick={onLinkClick}>
13
3
  <dx-tree-tile
4
+ href={href}
14
5
  is-root={isRoot}
15
6
  tree-node={treeNode}
16
7
  is-expanded={isExpanded}
@@ -39,7 +39,11 @@ export default class TreeItem extends LightningElement {
39
39
  }
40
40
 
41
41
  private get href(): string | undefined {
42
- return this._treeNode.link && this._treeNode.link.href;
42
+ return (
43
+ (this._treeNode.link && this._treeNode.link.href) ||
44
+ this._treeNode.name ||
45
+ ""
46
+ );
43
47
  }
44
48
 
45
49
  private get target(): string {
@@ -62,7 +66,11 @@ export default class TreeItem extends LightningElement {
62
66
  this.sendGtm(event, this.isExpanded ? "expand" : "collapse");
63
67
  }
64
68
 
65
- private onButtonClick(event: Event): void {
69
+ private onLinkClick(event: Event): void {
70
+ if (!(this._treeNode.link && this._treeNode.link.href)) {
71
+ event.preventDefault();
72
+ }
73
+
66
74
  if (this.hasChildren) {
67
75
  this.doExpand();
68
76
  }
@@ -71,10 +79,6 @@ export default class TreeItem extends LightningElement {
71
79
  this.fireEvent("tileselected", { name: this._treeNode.name });
72
80
  }
73
81
 
74
- private onLinkClick(event: Event): void {
75
- this.sendGtm(event, "click");
76
- }
77
-
78
82
  private doExpand(): void {
79
83
  this.isExpanded = !this.isExpanded;
80
84
  this.fireEvent("expandcollapse");
@@ -23,14 +23,15 @@ const assertLevelAndLabel = (container: HTMLElement) => {
23
23
  describe(TAG, () => {
24
24
  describe("render", () => {
25
25
  it("should render as a leaf tile", () => {
26
- const component = render({ treeNode: SINGLE_NODE });
27
- const tileDiv: HTMLElement = component.shadowRoot.querySelector(
28
- "div.tile"
26
+ const component = render({ treeNode: SINGLE_NODE, href: "/test" });
27
+ const tileAnchor: HTMLElement = component.shadowRoot.querySelector(
28
+ "a.tile"
29
29
  );
30
30
 
31
- expect(tileDiv.classList).toHaveLength(1);
32
- expect(tileDiv).not.toBeNull();
33
- assertLevelAndLabel(tileDiv);
31
+ expect(tileAnchor.getAttribute("href")).toBe("/test");
32
+ expect(tileAnchor.classList).toHaveLength(1);
33
+ expect(tileAnchor).not.toBeNull();
34
+ assertLevelAndLabel(tileAnchor);
34
35
 
35
36
  const arrowIcon: Icon = component.shadowRoot.querySelector(
36
37
  "dx-icon"
@@ -51,12 +52,12 @@ describe(TAG, () => {
51
52
  isRoot: true,
52
53
  hasChildren: true
53
54
  });
54
- const tileDiv: HTMLElement = component.shadowRoot.querySelector(
55
- "div.tile.tile-root"
55
+ const tileAnchor: HTMLElement = component.shadowRoot.querySelector(
56
+ "a.tile.tile-root"
56
57
  );
57
- expect(tileDiv).not.toBeNull();
58
- expect(tileDiv.classList).toHaveLength(2);
59
- assertLevelAndLabel(tileDiv);
58
+ expect(tileAnchor).not.toBeNull();
59
+ expect(tileAnchor.classList).toHaveLength(2);
60
+ assertLevelAndLabel(tileAnchor);
60
61
 
61
62
  const arrowIcon: Icon = component.shadowRoot.querySelector(
62
63
  "dx-icon"
@@ -79,13 +80,13 @@ describe(TAG, () => {
79
80
  hasChildren: true,
80
81
  isExpanded: true
81
82
  });
82
- const tileDiv: HTMLElement = component.shadowRoot.querySelector(
83
- "div.tile.tile-with-children"
83
+ const tileAnchor: HTMLElement = component.shadowRoot.querySelector(
84
+ "a.tile.tile-with-children"
84
85
  );
85
86
 
86
- expect(tileDiv).not.toBeNull();
87
- expect(tileDiv.classList).toHaveLength(2);
88
- assertLevelAndLabel(tileDiv);
87
+ expect(tileAnchor).not.toBeNull();
88
+ expect(tileAnchor.classList).toHaveLength(2);
89
+ assertLevelAndLabel(tileAnchor);
89
90
 
90
91
  const arrowIcon: Icon = component.shadowRoot.querySelector(
91
92
  "dx-icon"
@@ -107,11 +108,11 @@ describe(TAG, () => {
107
108
  treeNode: SINGLE_NODE,
108
109
  isSelected: true
109
110
  });
110
- const tileDiv: HTMLElement = component.shadowRoot.querySelector(
111
- "div.tile.tile-selected"
111
+ const tileAnchor: HTMLElement = component.shadowRoot.querySelector(
112
+ "a.tile.tile-selected"
112
113
  );
113
- expect(tileDiv).not.toBeNull();
114
- expect(tileDiv.classList).toHaveLength(2);
114
+ expect(tileAnchor).not.toBeNull();
115
+ expect(tileAnchor.classList).toHaveLength(2);
115
116
 
116
117
  return expect(component).toBeAccessible();
117
118
  });
@@ -34,6 +34,7 @@
34
34
  font-size: var(--dx-g-text-sm);
35
35
  font-weight: var(--dx-g-font-demi);
36
36
  color: var(--dx-g-blue-vibrant-30);
37
+ display: block;
37
38
  }
38
39
 
39
40
  .tile-selected {
@@ -188,3 +189,18 @@ dx-type-badge.delete {
188
189
  --dx-c-type-badge-color: var(--dx-g-red-vibrant-40);
189
190
  --dx-c-type-badge-background: var(--dx-g-hot-orange-vibrant-90);
190
191
  }
192
+
193
+ a {
194
+ display: block;
195
+ text-decoration: none;
196
+ }
197
+
198
+ a:link,
199
+ a:visited {
200
+ color: var(--dx-g-gray-10);
201
+ }
202
+
203
+ a:visited.tile-root,
204
+ a:link.tile-root {
205
+ color: var(--dx-g-blue-vibrant-30);
206
+ }
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class={tileClass}>
2
+ <a href={href} class={tileClass}>
3
3
  <div class="flex indentation" aria-level={tileAriaLevel}>
4
4
  <span class="tile-label truncate" title={treeNode.label}>
5
5
  {treeNode.label}
@@ -20,5 +20,5 @@
20
20
  value={methodText}
21
21
  ></dx-type-badge>
22
22
  </div>
23
- </div>
23
+ </a>
24
24
  </template>
@@ -18,6 +18,7 @@ export default class TreeTile extends LightningElement {
18
18
  @api isExpanded = false;
19
19
  @api hasChildren = false;
20
20
  @api isSelected = false;
21
+ @api href!: string;
21
22
 
22
23
  get tileAriaLevel() {
23
24
  return this.treeNode.level + 2;