Skip to content

Commit b1ce875

Browse files
Fix TreeView selection when loader is replaced with content
When a loader (spinner/skeleton) node is selected and replaced with actual content, the selection state (aria-selected) now properly transfers to the first loaded node. This ensures keyboard navigation maintains the expected selection state. Co-authored-by: francinelucca <[email protected]>
1 parent 679537d commit b1ce875

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

app/components/primer/alpha/tree_view/tree_view_sub_tree_node_element.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,15 @@ export class TreeViewSubTreeNodeElement extends HTMLElement {
279279
if (!content) return
280280

281281
content.focus()
282+
283+
// Set aria-selected on the newly focused node to maintain selection state
284+
// when the loader is replaced with actual content
285+
const treeView = this.closest('tree-view')
286+
if (treeView instanceof TreeViewElement) {
287+
const previousNode = treeView.querySelector('[aria-selected=true]')
288+
previousNode?.setAttribute('aria-selected', 'false')
289+
content.setAttribute('aria-selected', 'true')
290+
}
282291
}
283292

284293
this.#activeElementIsLoader = false

0 commit comments

Comments
 (0)