only emit a tree's selection change event when the selection has actually changed (#1030)

pull/1033/head
Tao Cumplido 2022-11-28 17:55:12 +01:00 zatwierdzone przez GitHub
rodzic 4dc92247d5
commit da6ae608f1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 7 dodań i 1 usunięć

Wyświetl plik

@ -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.