Skip to content

Commit

Permalink
Don't steal focus when removing focused tree items (#1430)
Browse files Browse the repository at this point in the history
* don't steal focus when removing focused tree items; #1428

* update PR link
  • Loading branch information
claviska authored Jul 6, 2023
1 parent c9e644f commit fe3906f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 6 deletions.
1 change: 1 addition & 0 deletions docs/pages/resources/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ New versions of Shoelace are released as-needed and generally occur when a criti
- Fixed a bug in `<sl-qr-code>` where the `background` attribute was never passed to the QR code [#1416]
- Fixed a bug in `<sl-dropdown>` where aria attributes were incorrectly applied to the default `<slot>` causing Lighthouse errors [#1417]
- Fixed a bug in `<sl-carousel>` that caused navigation to work incorrectly in some case [#1420]
- Fixed a bug in `<sl-tree>` that caused focus to be stolen when removing focused tree items [#1430]

## 2.5.2

Expand Down
6 changes: 0 additions & 6 deletions src/components/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,8 @@ 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 the focused item has been removed form the DOM, move the focus to the first focusable item
if (removedNodes.includes(this.lastFocusedItem)) {
this.focusItem(this.getFocusableItems()[0]);
}
}
};

Expand Down

0 comments on commit fe3906f

Please sign in to comment.