Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(desktop): focus comments from the full input area (#96328)

Peter Kirkham7478da2121b5
diff --git a/products/desktop/docs/TESTING.md b/products/desktop/docs/TESTING.md
index 81557f65e6a1..9c75941d4695 100644
--- a/products/desktop/docs/TESTING.md
+++ b/products/desktop/docs/TESTING.md
@@ -35,6 +35,19 @@ E2E-test:
Rule: if Electron is not required, write a unit test.
+## Comment Input Focus
+
+In the right-panel comment input, click an empty area below the placeholder or
+beside the send button. The editor must receive focus so you can type. Clicking
+existing text must keep the selected caret position. Send and cancel buttons must
+keep their own actions.
+
+Run the focus and submission checks with:
+
+```bash
+pnpm --filter @posthog/ui test src/features/sessions/components/CommentComposer.integration.test.tsx
+```
+
## File Location
- Unit tests colocate with source as `.test.ts` or `.test.tsx`.
diff --git a/products/desktop/packages/ui/src/features/canvas/components/MentionComposer.tsx b/products/desktop/packages/ui/src/features/canvas/components/MentionComposer.tsx
index 4a82f14e1686..4ab9a44ec184 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/MentionComposer.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/MentionComposer.tsx
@@ -296,7 +296,17 @@ export function MentionComposer({
</div>
</div>
)}
- <InputGroup className="h-auto cursor-text bg-card">
+ <InputGroup
+ className="h-auto cursor-text bg-card"
+ onClick={(event) => {
+ if (
+ event.target instanceof Element &&
+ !event.target.closest("button, [contenteditable]")
+ ) {
+ editor?.commands.focus("end");
+ }
+ }}
+ >
<div
data-slot="input-group-control"
className={`quill-input-group__control mention-composer w-full overflow-y-auto p-0 ${inputClassName ?? ""}`}
diff --git a/products/desktop/packages/ui/src/features/sessions/components/CommentComposer.integration.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/CommentComposer.integration.test.tsx
index 8eefc42881b7..4d4674a7461f 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/CommentComposer.integration.test.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/CommentComposer.integration.test.tsx
@@ -1,8 +1,57 @@
-import { fireEvent, render, screen } from "@testing-library/react";
+import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { CommentComposer } from "./CommentComposer";
-describe("CommentComposer submission", () => {
+describe("CommentComposer", () => {
+ it.each(["input-group", "input-group-control", "input-group-addon"])(
+ "focuses the editor when clicking the empty %s area",
+ async (slot) => {
+ const { container } = render(
+ <CommentComposer
+ value=""
+ onValueChange={vi.fn()}
+ onSubmit={vi.fn()}
+ members={[]}
+ placeholder="Comment"
+ />,
+ );
+
+ const area = container.querySelector(`[data-slot="${slot}"]`);
+ expect(area).not.toBeNull();
+ fireEvent.click(area as Element);
+
+ await waitFor(() =>
+ expect(container.querySelector(".ProseMirror")).toHaveFocus(),
+ );
+ },
+ );
+
+ it.each(["Comment", "Cancel"])(
+ "keeps focus on the %s button when clicked",
+ async (label) => {
+ const onSubmit = vi.fn();
+ const onCancel = vi.fn();
+ render(
+ <CommentComposer
+ value="Check this"
+ onValueChange={vi.fn()}
+ onSubmit={onSubmit}
+ onCancel={onCancel}
+ members={[]}
+ placeholder="Comment"
+ />,
+ );
+
+ const button = screen.getByRole("button", { name: label });
+ button.focus();
+ fireEvent.click(button.querySelector("svg") as SVGElement);
+ await new Promise(requestAnimationFrame);
+
+ expect(button).toHaveFocus();
+ expect(label === "Comment" ? onSubmit : onCancel).toHaveBeenCalledOnce();
+ },
+ );
+
it.each(["enter", "send"] as const)(
"submits the current comment with %s",
(input) => {
diff --git a/products/desktop/packages/ui/src/features/sessions/components/CommentComposer.stories.tsx b/products/desktop/packages/ui/src/features/sessions/components/CommentComposer.stories.tsx
new file mode 100644
index 000000000000..b75d53e92094
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/sessions/components/CommentComposer.stories.tsx
@@ -0,0 +1,35 @@
+import type { Meta, StoryObj } from "@storybook/react-vite";
+import { useState } from "react";
+import { CommentComposer } from "./CommentComposer";
+
+const meta = {
+ title: "Sessions/CommentComposer",
+ component: CommentComposer,
+ parameters: { layout: "centered" },
+ args: {
+ value: "",
+ members: [],
+ placeholder: "Add a comment…",
+ onValueChange: () => {},
+ onSubmit: () => {},
+ },
+ render: function Composer(args) {
+ const [value, setValue] = useState(args.value);
+ return (
+ <div className="w-80">
+ <CommentComposer
+ {...args}
+ value={value}
+ onValueChange={setValue}
+ onSubmit={() => setValue("")}
+ />
+ </div>
+ );
+ },
+} satisfies Meta<typeof CommentComposer>;
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+export const Empty: Story = {};
+export const WithText: Story = { args: { value: "Check the updated layout." } };