Skip to content

Commit 2c73c52

Browse files
vaststudiosclaude
andcommitted
fix(web): keyboard focus stays on the thread list buttons while paging
The last "Show more" step and the first "Show less" step unmount the button that was just pressed, which dropped keyboard focus to the page. Focus now moves to the button that remains. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5fe6e46 commit 2c73c52

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

‎apps/web/src/components/LegacySidebar.tsx‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,18 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList(
980980
} = props;
981981
const showMoreButtonRender = <button type="button" />;
982982
const showLessButtonRender = <button type="button" />;
983+
// A step can unmount the button that was just pressed; hand its focus to the one that remains.
984+
const stepThreadList = (event: React.MouseEvent<HTMLElement>, steps: number) => {
985+
const button = event.currentTarget;
986+
const group = button.parentElement;
987+
const hadFocus = button === document.activeElement;
988+
setThreadListSteps(projectKey, steps);
989+
requestAnimationFrame(() => {
990+
if (hadFocus && group?.isConnected && !group.contains(document.activeElement)) {
991+
group.querySelector("button")?.focus();
992+
}
993+
});
994+
};
983995

984996
return (
985997
<SidebarMenuSub
@@ -1039,9 +1051,7 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList(
10391051
render={showMoreButtonRender}
10401052
data-thread-selection-safe
10411053
size="sm"
1042-
onClick={() => {
1043-
setThreadListSteps(projectKey, threadListWindow.steps + 1);
1044-
}}
1054+
onClick={(event) => stepThreadList(event, threadListWindow.steps + 1)}
10451055
>
10461056
<span className="flex min-w-0 flex-1 items-center gap-2">
10471057
{hiddenThreadStatus && <ThreadStatusLabel status={hiddenThreadStatus} compact />}
@@ -1054,9 +1064,7 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList(
10541064
render={showLessButtonRender}
10551065
data-thread-selection-safe
10561066
size="sm"
1057-
onClick={() => {
1058-
setThreadListSteps(projectKey, threadListWindow.steps - 1);
1059-
}}
1067+
onClick={(event) => stepThreadList(event, threadListWindow.steps - 1)}
10601068
>
10611069
<span>Show less</span>
10621070
</SidebarMenuSubButton>

0 commit comments

Comments
 (0)