Skip to content

Commit c8e6f4f

Browse files
anveshmekalaisaacbraun
authored andcommitted
fix(tree-item): restore selection icon to bullet when selection-mode='single'|'single-persist'|'children' (#13915)
**Related Issue:** #13817 Restores selection icon to bullet-point when `selection-mode='single'|'single-persist'|'children'`
1 parent 59f2338 commit c8e6f4f

5 files changed

Lines changed: 33 additions & 18 deletions

File tree

packages/components/src/components/tree-item/resources.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ export const CSS = {
55
checkbox: "checkbox",
66
checkboxContainer: "checkbox-container",
77
checkboxLabel: "checkbox-label",
8-
checkmarkIcon: "checkmark",
98
chevron: "chevron",
109
childrenContainer: "children-container",
1110
iconStart: "icon-start",
1211
itemExpanded: "item--expanded",
1312
nodeAndActionsContainer: "node-actions-container",
1413
nodeContainer: "node-container",
14+
selectionIcon: "selection-icon",
1515
};
1616

1717
export const SLOTS = {
@@ -21,6 +21,7 @@ export const SLOTS = {
2121

2222
export const ICONS: Record<string, IconName> = {
2323
blank: "blank",
24+
bulletPoint: "bullet-point",
2425
checkmark: "check",
2526
checkSquareF: "check-square-f",
2627
chevronRight: "chevron-right",

packages/components/src/components/tree-item/tree-item.e2e.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ describe("calcite-tree-item", () => {
472472
},
473473
"--calcite-tree-selected-icon-color": {
474474
targetProp: "color",
475-
shadowSelector: `.${CSS.checkmarkIcon}`,
475+
shadowSelector: `.${CSS.selectionIcon}`,
476476
selector: "calcite-tree-item",
477477
},
478478
},
@@ -486,7 +486,7 @@ describe("calcite-tree-item", () => {
486486
{
487487
"--calcite-tree-selected-icon-color": {
488488
targetProp: "color",
489-
shadowSelector: `.${CSS.checkmarkIcon}`,
489+
shadowSelector: `.${CSS.selectionIcon}`,
490490
selector: "calcite-tree-item",
491491
},
492492
},

packages/components/src/components/tree-item/tree-item.scss

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@
178178

179179
.node-container {
180180
@apply relative flex grow items-center min-w-0;
181-
182-
.checkmark {
181+
.selection-icon {
183182
@apply transition-default opacity-0;
184183
color: var(--calcite-color-border-1);
185184
}
@@ -188,7 +187,7 @@
188187
.node-container:hover,
189188
:host([selected]) .node-container:hover,
190189
:host(:focus:not([disabled])) .node-container {
191-
.checkmark {
190+
.selection-icon {
192191
@apply opacity-100;
193192
}
194193
}
@@ -204,15 +203,15 @@
204203
--calcite-icon-color: var(--calcite-internal-tree-item-text-color);
205204
}
206205

207-
.checkmark {
206+
.selection-icon {
208207
@apply opacity-100;
209208
color: var(--calcite-tree-selected-icon-color, var(--calcite-color-brand));
210209
}
211210
}
212211

213212
// dropdown with children
214213
:host([has-children]) .node-container {
215-
.checkmark {
214+
.selection-icon {
216215
@apply hidden;
217216
}
218217
}
@@ -235,7 +234,7 @@
235234
}
236235

237236
:host([selected]) {
238-
.checkmark {
237+
.selection-icon {
239238
color: var(--calcite-tree-selected-icon-color, var(--calcite-color-brand));
240239
}
241240
.checkbox {

packages/components/src/components/tree-item/tree-item.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,29 @@ export class TreeItem extends LitElement {
360360
}
361361
}
362362

363+
private getSelectionIcon(): IconName {
364+
const { selectionMode, hasChildren } = this;
365+
if (
366+
selectionMode === "single" ||
367+
selectionMode === "children" ||
368+
selectionMode === "single-persist"
369+
) {
370+
return ICONS.bulletPoint;
371+
} else if (selectionMode === "multiple" || selectionMode === "multichildren") {
372+
return ICONS.checkmark;
373+
} else if (selectionMode === "none" && !hasChildren) {
374+
return ICONS.blank;
375+
}
376+
return null;
377+
}
378+
363379
//#endregion
364380

365381
//#region Rendering
366382

367383
override render(): JsxNode {
368384
const rtl = getElementDir(this.el) === "rtl";
369-
const showCheckmark = this.selectionMode !== "none" && this.selectionMode !== "ancestors";
370-
const showBlank = this.selectionMode === "none" && !this.hasChildren;
385+
const selectionIcon = this.getSelectionIcon();
371386
const checkboxIsIndeterminate = this.hasChildren && this.indeterminate;
372387

373388
const chevron =
@@ -401,14 +416,14 @@ export class TreeItem extends LitElement {
401416
/>
402417
</div>
403418
) : null;
404-
const selectedIcon = showCheckmark ? ICONS.checkmark : showBlank ? ICONS.blank : null;
405-
const itemIndicator = selectedIcon ? (
419+
420+
const itemIndicator = selectionIcon ? (
406421
<calcite-icon
407422
class={{
408-
[CSS.checkmarkIcon]: selectedIcon === ICONS.checkmark,
423+
[CSS.selectionIcon]: true,
409424
[CSS_UTILITY.rtl]: rtl,
410425
}}
411-
icon={selectedIcon}
426+
icon={selectionIcon}
412427
scale={getIconScale(this.scale)}
413428
/>
414429
) : null;

packages/components/src/components/tree/tree.stories.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export default {
5757
},
5858
};
5959

60-
const treeItems = (expanded = true) => html`
61-
<calcite-tree-item label="test item">
60+
const treeItems = (expanded = true, isSelectionModeNone = false) => html`
61+
<calcite-tree-item label="test item" ${!isSelectionModeNone ? "selected" : ""}>
6262
<a>Child 1</a>
6363
</calcite-tree-item>
6464
<calcite-tree-item label="test item" icon-start="palette" ${expanded ? "expanded" : ""}>
@@ -144,7 +144,7 @@ export const singleSelectionMode = (): string => html` ${treeItems()} `;
144144
singleSelectionMode.decorators = [allScaleTreeBuilder];
145145
singleSelectionMode.args = { selectionMode: "single" };
146146

147-
export const selectionModeNone = (): string => html`${treeItems()}`;
147+
export const selectionModeNone = (): string => html`${treeItems(true, true)}`;
148148
selectionModeNone.decorators = [allScaleTreeBuilder];
149149
selectionModeNone.args = { selectionMode: "none" };
150150

0 commit comments

Comments
 (0)