Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SlTree: separate expand/collapse and selection behaviour in 'single' mode #1521

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions src/components/tree/tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,6 @@ export default class SlTree extends ShoelaceElement {
}
};

private syncTreeItems(selectedItem: SlTreeItem) {
const items = this.getAllTreeItems();

if (this.selection === 'multiple') {
syncCheckboxes(selectedItem);
} else {
for (const item of items) {
if (item !== selectedItem) {
item.selected = false;
}
}
}
}

private selectItem(selectedItem: SlTreeItem) {
const previousSelection = [...this.selectedItems];

Expand All @@ -190,12 +176,12 @@ export default class SlTree extends ShoelaceElement {
if (selectedItem.lazy) {
selectedItem.expanded = true;
}
this.syncTreeItems(selectedItem);
syncCheckboxes(selectedItem);
} else if (this.selection === 'single' || selectedItem.isLeaf) {
selectedItem.expanded = !selectedItem.expanded;
selectedItem.selected = true;

this.syncTreeItems(selectedItem);
const items = this.getAllTreeItems();
for (const item of items) {
item.selected = (item === selectedItem);
}
} else if (this.selection === 'leaf') {
selectedItem.expanded = !selectedItem.expanded;
}
Expand Down Expand Up @@ -311,7 +297,7 @@ export default class SlTree extends ShoelaceElement {
return;
}

if (this.selection === 'multiple' && isExpandButton) {
if (isExpandButton) {
treeItem.expanded = !treeItem.expanded;
} else {
this.selectItem(treeItem);
Expand Down
Loading