TypeScript
fix(web): settling a thread no longer scrolls the sidebar to the bottom (#26392)
Theo Browne40d335a7ba8e
diff --git a/apps/web/src/lib/sidebarTree.browser.test.ts b/apps/web/src/lib/sidebarTree.browser.test.tsindex 3d57aacb864..6b02cd3b842 100644--- a/apps/web/src/lib/sidebarTree.browser.test.ts+++ b/apps/web/src/lib/sidebarTree.browser.test.ts@@ -172,6 +172,25 @@ describe("sidebar keyboard navigation", () => {expect([firstAction.tabIndex, secondAction.tabIndex]).toEqual([-1, 0]);});+ it("keeps the scroll position when focus follows a row that moved away", async () => {+ using tree = setup();+ Object.assign(tree.root.style, { height: "100px", overflow: "auto" });+ const settled = tree.row("settled");+ const settle = document.createElement("button");+ settle.textContent = "Settle";+ settled.after(settle);+ settle.dataset.sidebarActionFor = "settled";+ for (let index = 0; index < 20; index++) tree.row(`row-${index}`).style.display = "block";+ tree.install();+ settle.focus();+ // Settling moves the row to the shelf at the bottom and removes the focused button.+ settle.remove();+ settled.remove();+ const moved = tree.row("settled");+ await vi.waitFor(() => expect(document.activeElement).toBe(moved));+ expect(tree.root.scrollTop).toBe(0);+ });+it("does not pull focus back after a click outside the tree", async () => {using tree = setup();const first = tree.row("first");diff --git a/apps/web/src/lib/sidebarTree.ts b/apps/web/src/lib/sidebarTree.tsindex 13dd10340e0..07859c72bd9 100644--- a/apps/web/src/lib/sidebarTree.ts+++ b/apps/web/src/lib/sidebarTree.ts@@ -120,7 +120,8 @@ export function installSidebarTree(root: HTMLElement) {!rows.includes(document.activeElement as HTMLElement) &&document.activeElement?.matches(ROW)))) {- focusRow(selected);+ // A settled row moves to the bottom shelf; scrolling after it fights the route reveal.+ selected.focus({ preventScroll: true });}if (ownsFocus && !selected && document.activeElement === document.body) root.focus();};