mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 12:09:26 +00:00
only emit a tree's selection change event when the selection has actually changed (#1030)
This commit is contained in:
@@ -177,6 +177,8 @@ export default class SlTree extends ShoelaceElement {
|
||||
}
|
||||
|
||||
selectItem(selectedItem: SlTreeItem) {
|
||||
const previousSelection = [...this.selectedItems];
|
||||
|
||||
if (this.selection === 'multiple') {
|
||||
selectedItem.selected = !selectedItem.selected;
|
||||
if (selectedItem.lazy) {
|
||||
@@ -192,7 +194,11 @@ export default class SlTree extends ShoelaceElement {
|
||||
selectedItem.expanded = !selectedItem.expanded;
|
||||
}
|
||||
|
||||
this.emit('sl-selection-change', { detail: { selection: this.selectedItems } });
|
||||
const nextSelection = this.selectedItems;
|
||||
|
||||
if (nextSelection.some(item => !previousSelection.includes(item))) {
|
||||
this.emit('sl-selection-change', { detail: { selection: nextSelection } });
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the list of tree items that are selected in the tree.
|
||||
|
||||
Reference in New Issue
Block a user