Skip to content

Commit

Permalink
unset last focused item; #1436 (#1446)
Browse files Browse the repository at this point in the history
  • Loading branch information
claviska authored Jul 12, 2023
1 parent 8fd01e1 commit 414197a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class SlTree extends ShoelaceElement {
// A collection of all the items in the tree, in the order they appear. The collection is live, meaning it is
// automatically updated when the underlying document is changed.
//
private lastFocusedItem: SlTreeItem;
private lastFocusedItem: SlTreeItem | null;
private readonly localize = new LocalizeController(this);
private mutationObserver: MutationObserver;
private clickTarget: SlTreeItem | null = null;
Expand Down Expand Up @@ -159,8 +159,13 @@ export default class SlTree extends ShoelaceElement {
private handleTreeChanged = (mutations: MutationRecord[]) => {
for (const mutation of mutations) {
const addedNodes: SlTreeItem[] = [...mutation.addedNodes].filter(SlTreeItem.isTreeItem) as SlTreeItem[];
const removedNodes = [...mutation.removedNodes].filter(SlTreeItem.isTreeItem) as SlTreeItem[];

addedNodes.forEach(this.initTreeItem);

if (this.lastFocusedItem && removedNodes.includes(this.lastFocusedItem)) {
this.lastFocusedItem = null;
}
}
};

Expand Down

0 comments on commit 414197a

Please sign in to comment.