Skip to content

Commit bbccb42

Browse files
juliusmarmingecodex
andcommitted
fix(web): preserve desktop composer action focus
Only prevent primary action pointer focus on mobile composer surfaces that need to keep the editor active. Co-authored-by: codex <[email protected]>
1 parent 35b4b8b commit bbccb42

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
302302
isSendBusy: boolean;
303303
isConnecting: boolean;
304304
hasSendableContent: boolean;
305+
preserveComposerFocusOnPointerDown?: boolean;
305306
onPreviousPendingQuestion: () => void;
306307
onInterrupt: () => void;
307308
onImplementPlanInNewThread: () => void;
@@ -322,6 +323,7 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
322323
isConnecting={props.isConnecting}
323324
isPreparingWorktree={props.isPreparingWorktree}
324325
hasSendableContent={props.hasSendableContent}
326+
preserveComposerFocusOnPointerDown={props.preserveComposerFocusOnPointerDown ?? false}
325327
onPreviousPendingQuestion={props.onPreviousPendingQuestion}
326328
onInterrupt={props.onInterrupt}
327329
onImplementPlanInNewThread={props.onImplementPlanInNewThread}
@@ -2070,6 +2072,7 @@ export const ChatComposer = memo(
20702072
isConnecting={isConnecting}
20712073
isPreparingWorktree={false}
20722074
hasSendableContent={false}
2075+
preserveComposerFocusOnPointerDown
20732076
onPreviousPendingQuestion={onPreviousActivePendingUserInputQuestion}
20742077
onInterrupt={handleInterruptPrimaryAction}
20752078
onImplementPlanInNewThread={handleImplementPlanInNewThreadPrimaryAction}
@@ -2268,6 +2271,7 @@ export const ChatComposer = memo(
22682271
isConnecting={isConnecting}
22692272
isPreparingWorktree={false}
22702273
hasSendableContent={false}
2274+
preserveComposerFocusOnPointerDown
22712275
onPreviousPendingQuestion={onPreviousActivePendingUserInputQuestion}
22722276
onInterrupt={handleInterruptPrimaryAction}
22732277
onImplementPlanInNewThread={handleImplementPlanInNewThreadPrimaryAction}
@@ -2382,6 +2386,7 @@ export const ChatComposer = memo(
23822386
isConnecting={isConnecting}
23832387
isPreparingWorktree={isPreparingWorktree}
23842388
hasSendableContent={composerSendState.hasSendableContent}
2389+
preserveComposerFocusOnPointerDown={isMobileViewport}
23852390
onPreviousPendingQuestion={onPreviousActivePendingUserInputQuestion}
23862391
onInterrupt={handleInterruptPrimaryAction}
23872392
onImplementPlanInNewThread={handleImplementPlanInNewThreadPrimaryAction}

‎apps/web/src/components/chat/ComposerPrimaryActions.tsx‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { memo } from "react";
1+
import { memo, type PointerEventHandler } from "react";
22
import { ChevronDownIcon, ChevronLeftIcon } from "lucide-react";
33
import { cn } from "~/lib/utils";
44
import { Button } from "../ui/button";
@@ -22,6 +22,7 @@ interface ComposerPrimaryActionsProps {
2222
isConnecting: boolean;
2323
isPreparingWorktree: boolean;
2424
hasSendableContent: boolean;
25+
preserveComposerFocusOnPointerDown?: boolean;
2526
onPreviousPendingQuestion: () => void;
2627
onInterrupt: () => void;
2728
onImplementPlanInNewThread: () => void;
@@ -45,6 +46,10 @@ export const formatPendingPrimaryActionLabel = (input: {
4546
return input.questionIndex > 0 ? "Submit answers" : "Submit answer";
4647
};
4748

49+
const preventPointerFocus: PointerEventHandler<HTMLElement> = (event) => {
50+
event.preventDefault();
51+
};
52+
4853
export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
4954
compact,
5055
pendingAction,
@@ -55,10 +60,15 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
5560
isConnecting,
5661
isPreparingWorktree,
5762
hasSendableContent,
63+
preserveComposerFocusOnPointerDown = false,
5864
onPreviousPendingQuestion,
5965
onInterrupt,
6066
onImplementPlanInNewThread,
6167
}: ComposerPrimaryActionsProps) {
68+
const pointerFocusProps = preserveComposerFocusOnPointerDown
69+
? { onPointerDown: preventPointerFocus }
70+
: undefined;
71+
6272
if (pendingAction) {
6373
return (
6474
<div className={cn("flex items-center justify-end", compact ? "gap-1.5" : "gap-2")}>
@@ -68,7 +78,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
6878
size="icon-sm"
6979
variant="outline"
7080
className="rounded-full"
71-
onPointerDown={(event) => event.preventDefault()}
81+
{...pointerFocusProps}
7282
onClick={onPreviousPendingQuestion}
7383
disabled={pendingAction.isResponding}
7484
aria-label="Previous question"
@@ -80,7 +90,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
8090
size="sm"
8191
variant="outline"
8292
className="rounded-full"
83-
onPointerDown={(event) => event.preventDefault()}
93+
{...pointerFocusProps}
8494
onClick={onPreviousPendingQuestion}
8595
disabled={pendingAction.isResponding}
8696
>
@@ -92,7 +102,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
92102
type="submit"
93103
size="sm"
94104
className={cn("rounded-full", compact ? "px-3" : "px-4")}
95-
onPointerDown={(event) => event.preventDefault()}
105+
{...pointerFocusProps}
96106
disabled={
97107
pendingAction.isResponding ||
98108
(pendingAction.isLastQuestion ? !pendingAction.isComplete : !pendingAction.canAdvance)
@@ -114,7 +124,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
114124
<button
115125
type="button"
116126
className="flex size-8 cursor-pointer items-center justify-center rounded-full bg-rose-500/90 text-white transition-all duration-150 hover:bg-rose-500 hover:scale-105 sm:h-8 sm:w-8"
117-
onPointerDown={(event) => event.preventDefault()}
127+
{...pointerFocusProps}
118128
onClick={onInterrupt}
119129
aria-label="Stop generation"
120130
>
@@ -132,7 +142,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
132142
type="submit"
133143
size="sm"
134144
className={cn("rounded-full", compact ? "h-9 px-3 sm:h-8" : "h-9 px-4 sm:h-8")}
135-
onPointerDown={(event) => event.preventDefault()}
145+
{...pointerFocusProps}
136146
disabled={isSendBusy || isConnecting}
137147
>
138148
{isConnecting || isSendBusy ? "Sending..." : "Refine"}
@@ -146,7 +156,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
146156
type="submit"
147157
size="sm"
148158
className="h-9 rounded-l-full rounded-r-none px-4 sm:h-8"
149-
onPointerDown={(event) => event.preventDefault()}
159+
{...pointerFocusProps}
150160
disabled={isSendBusy || isConnecting}
151161
>
152162
{isConnecting || isSendBusy ? "Sending..." : "Implement"}
@@ -159,7 +169,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
159169
variant="default"
160170
className="h-9 rounded-l-none rounded-r-full border-l-white/12 px-2 sm:h-8"
161171
aria-label="Implementation actions"
162-
onPointerDown={(event) => event.preventDefault()}
172+
{...pointerFocusProps}
163173
disabled={isSendBusy || isConnecting}
164174
/>
165175
}
@@ -183,7 +193,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
183193
<button
184194
type="submit"
185195
className="flex h-9 w-9 enabled:cursor-pointer items-center justify-center rounded-full bg-primary/90 text-primary-foreground transition-all duration-150 hover:bg-primary hover:scale-105 disabled:pointer-events-none disabled:opacity-30 disabled:hover:scale-100 sm:h-8 sm:w-8"
186-
onPointerDown={(event) => event.preventDefault()}
196+
{...pointerFocusProps}
187197
disabled={isSendBusy || isConnecting || !hasSendableContent}
188198
aria-label={
189199
isConnecting

0 commit comments

Comments
 (0)