Skip to content

Commit 7821383

Browse files
committed
fix(web): J and K step the PR guide while the panel is maximized, and after a stop button
A maximized panel hides the chat column, so typing no longer goes into its composer. Stepping from a button inside the stop keeps focus in the guide instead of dropping it to the page.
1 parent 4a2a04c commit 7821383

3 files changed

Lines changed: 28 additions & 9 deletions

File tree

‎apps/web/src/components/chat/composerFocusRedirect.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export function shouldRedirectInputToComposer(event: Event): boolean {
7878
if (eventPathContainsSelector(event, TYPE_TO_FOCUS_EDITABLE_SELECTOR)) return false;
7979
if (eventPathContainsSelector(event, TYPE_TO_FOCUS_INTERACTIVE_SELECTOR)) return false;
8080
if (document.querySelector(TYPE_TO_FOCUS_FLOATING_LAYER_SELECTOR)) return false;
81+
if (document.querySelector('[data-chat-column-maximized-away="true"]')) return false;
8182
return true;
8283
}
8384

‎apps/web/src/components/pullRequest/PullRequestGuideTab.browser.test.tsx‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@ const threeStopGuide: PullRequestReviewGuide = {
100100
})),
101101
};
102102

103-
function ChatBeside({ composerKeys }: { composerKeys: string[] }) {
103+
function ChatBeside({
104+
composerKeys,
105+
maximizedAway,
106+
}: {
107+
composerKeys: string[];
108+
maximizedAway: boolean;
109+
}) {
104110
useChatShortcuts({
105111
enabled: true,
106112
keybindings: [],
@@ -128,10 +134,10 @@ function ChatBeside({ composerKeys }: { composerKeys: string[] }) {
128134
commands: {},
129135
fallback: () => undefined,
130136
});
131-
return null;
137+
return <div data-chat-column-maximized-away={maximizedAway ? "true" : "false"} />;
132138
}
133139

134-
it("steps with J and K after a click on guide prose beside a chat", async () => {
140+
it("steps with J and K beside a chat, also after a stop button or while the chat is maximized away", async () => {
135141
vi.mocked(useReviewGuideWriter).mockReturnValue({
136142
query: { isPending: false, error: null } as never,
137143
data: { guide: threeStopGuide, run: null, currentHeadSha: "head" },
@@ -141,9 +147,9 @@ it("steps with J and K after a click on guide prose beside a chat", async () =>
141147
});
142148
const composerKeys: string[] = [];
143149

144-
await using screen = await render(
150+
const tree = (maximizedAway: boolean) => (
145151
<>
146-
<ChatBeside composerKeys={composerKeys} />
152+
<ChatBeside composerKeys={composerKeys} maximizedAway={maximizedAway} />
147153
<PullRequestGuideTab
148154
environmentId={EnvironmentId.make("environment")}
149155
reference={reference}
@@ -158,11 +164,18 @@ it("steps with J and K after a click on guide prose beside a chat", async () =>
158164
onFinishReview={null}
159165
onOpenFile={() => {}}
160166
/>
161-
</>,
167+
</>
162168
);
169+
await using screen = await render(tree(true));
163170

164-
await userEvent.click(screen.getByText("Prose for the first stop."));
165-
await userEvent.keyboard("jj");
171+
await userEvent.keyboard("j");
172+
await expect.element(screen.getByText("Prose for the second stop.")).toBeVisible();
173+
await screen.rerender(tree(false));
174+
await userEvent.click(screen.getByText("Prose for the second stop."));
175+
await userEvent.keyboard("k");
176+
await expect.element(screen.getByText("Prose for the first stop.")).toBeVisible();
177+
await userEvent.click(screen.getByRole("button", { name: "Next stop" }));
178+
await userEvent.keyboard("j");
166179
await expect.element(screen.getByText("Prose for the third stop.")).toBeVisible();
167180
await userEvent.keyboard("k");
168181
await expect.element(screen.getByText("Prose for the second stop.")).toBeVisible();

‎apps/web/src/components/pullRequest/guide/GuideTour.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ export function GuideTour({
6868
});
6969

7070
const scrollRef = useRef<HTMLDivElement>(null);
71+
const railRef = useRef<HTMLElement>(null);
7172
const goTo = (next: number) => {
73+
const focused = document.activeElement;
74+
if (scrollRef.current?.contains(focused) && !railRef.current?.contains(focused)) {
75+
scrollRef.current.focus({ preventScroll: true });
76+
}
7277
update((current) => ({
7378
position: next,
7479
seen: next > position ? new Set(current.seen).add(position) : current.seen,
@@ -103,7 +108,7 @@ export function GuideTour({
103108
className="@container/guide h-full overflow-y-auto scrollbar-gutter-both outline-none"
104109
>
105110
<div className="mx-auto grid max-w-[100rem] gap-6 px-4 py-4 @min-[56rem]/guide:grid-cols-[16rem_minmax(0,1fr)] @min-[90rem]/guide:gap-8 @min-[90rem]/guide:px-6">
106-
<aside className="sticky top-4 self-start @max-[56rem]/guide:hidden">
111+
<aside ref={railRef} className="sticky top-4 self-start @max-[56rem]/guide:hidden">
107112
<GuideRail stops={guide.stops} position={position} seen={tour.seen} onSelect={goTo} />
108113
</aside>
109114
<main className="flex min-w-0 flex-col gap-4">

0 commit comments

Comments
 (0)