Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,21 @@ export const CompactionHintSurvivesOverrideFetchError: Story = {
},
};

export const ComposerFocusedWithKeyboard: Story = {
parameters: {
queries: buildQueries(MockChat, {
messages: [],
queued_messages: [],
has_more: false,
}),
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
(await canvas.findByRole("button", { name: "More options" })).focus();
await userEvent.tab({ shift: true });
},
};

/** Multi-turn conversation with rich markdown rendering: headings, tables,
* ordered/unordered lists, nested lists, code blocks, blockquotes,
* horizontal rules, inline formatting, links, images, and task lists. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ export const AgentChatPageView: React.FC<AgentChatPageViewProps> = ({
}
/>
{!isArchived && (
<div className="shrink-0 overflow-y-auto px-4 pb-3 md:pb-0 scrollbar-gutter-stable scrollbar-thin">
<div className="-mt-0.5 shrink-0 overflow-y-auto px-4 pt-0.5 pb-3 md:pb-0 scrollbar-gutter-stable scrollbar-thin">
<ChatPageInput
chat={chat}
store={store}
Expand Down Expand Up @@ -1075,7 +1075,7 @@ export const AgentChatPageLoadingView: React.FC<
</div>
</div>
</div>
<div className="shrink-0 overflow-y-auto px-4 pb-3 md:pb-0 scrollbar-gutter-stable scrollbar-thin">
<div className="-mt-0.5 shrink-0 overflow-y-auto px-4 pt-0.5 pb-3 md:pb-0 scrollbar-gutter-stable scrollbar-thin">
<AgentChatInput
onSend={() => {}}
inputRef={inputRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ const getEditor = (canvasElement: HTMLElement) =>

export const Default: Story = {};

export const ComposerFocusedWithKeyboard: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
canvas.getByRole("button", { name: "More options" }).focus();
await userEvent.tab({ shift: true });
},
};

export const PromptHistoryCycling: Story = {
args: {
userPromptHistory: promptHistory,
Expand Down
37 changes: 36 additions & 1 deletion site/src/pages/AgentsPage/components/AgentChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,24 @@ export const AgentChatInput: React.FC<AgentChatInputProps> = ({
(providerCount === 0 || modelCount === 0)
: modelCount !== undefined && modelCount === 0);
const internalRef = useRef<ChatMessageInputRef>(null);
// Browsers treat any contenteditable focus as focus-visible, including
// autofocus, so only ring focus that arrived via Tab.
const lastInputWasTabRef = useRef(false);
const [isEditorKeyboardFocused, setIsEditorKeyboardFocused] = useState(false);
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
lastInputWasTabRef.current = event.key === "Tab";
};
const handlePointerDown = () => {
lastInputWasTabRef.current = false;
};
document.addEventListener("keydown", handleKeyDown, true);
document.addEventListener("pointerdown", handlePointerDown, true);
return () => {
document.removeEventListener("keydown", handleKeyDown, true);
document.removeEventListener("pointerdown", handlePointerDown, true);
};
}, []);
const [previewImage, setPreviewImage] = useState<string | null>(null);
const [previewText, setPreviewText] = useState<string | null>(null);
const [previewTextFileName, setPreviewTextFileName] = useState<string | null>(
Expand Down Expand Up @@ -1403,14 +1421,31 @@ export const AgentChatInput: React.FC<AgentChatInputProps> = ({
ref={setComposerElement}
data-testid="chat-composer"
className={cn(
"relative z-10 rounded-2xl bg-surface-secondary sm:bg-surface-secondary/45 p-1 shadow-xs has-[textarea:focus]:ring-2 has-[textarea:focus]:ring-content-link/40",
"relative z-10 rounded-2xl bg-surface-secondary sm:bg-surface-secondary/45 p-1 shadow-xs",
isEditorKeyboardFocused && "ring-2 ring-content-link",
showAgentSetupNotice && "sm:bg-surface-secondary",
isDragging && "ring-2 ring-content-link/40",
(isEditingHistoryMessage || warning) &&
"shadow-[0_0_0_2px_hsla(var(--border-warning),0.6)]",
isReadOnlyView && "border border-solid border-border",
)}
onKeyDown={handleComposerKeyDown}
onFocus={(event) => {
if (
event.target instanceof HTMLElement &&
event.target.isContentEditable
) {
setIsEditorKeyboardFocused(lastInputWasTabRef.current);
}
}}
onBlur={(event) => {
if (
event.target instanceof HTMLElement &&
event.target.isContentEditable
) {
setIsEditorKeyboardFocused(false);
}
}}
onDragOver={onAttach ? handleDragOver : undefined}
onDragLeave={onAttach ? handleDragLeave : undefined}
onDrop={onAttach ? handleDrop : undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export const AgentCreateFormFrame: React.FC<React.PropsWithChildren> = ({
children,
}) => (
<div className="order-last flex min-h-0 flex-none items-end justify-center overflow-auto px-4 pb-4 sm:order-0 sm:h-full sm:flex-1 sm:items-center">
<div className="order-last -mt-0.5 flex min-h-0 flex-none items-end justify-center overflow-auto px-4 pt-0.5 pb-4 sm:order-0 sm:h-full sm:flex-1 sm:items-center">
<div className="mx-auto w-full max-w-3xl">{children}</div>
</div>
);
Loading