Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(open-knowledge): focus Ask AI input on composer whitespace click (#2518)

sarahbbe6c42fad1d
diff --git a/.changeset/ask-ai-composer-click-to-focus.md b/.changeset/ask-ai-composer-click-to-focus.md
new file mode 100644
index 000000000..cc1f118dc
--- /dev/null
+++ b/.changeset/ask-ai-composer-click-to-focus.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Clicking anywhere in an Ask AI composer now focuses its input. Previously only the text itself was a focus target, so the padding around the field, the gaps beside the send button, and the empty space in the card were dead — a click there did nothing. Both composers get the standard chat-composer behavior: the bottom docked composer (open-doc and folder-overview modes) and the empty-state "Create with AI" composer. Keyboard and screen-reader users are unaffected — the input keeps its own semantics and is still reached directly via Tab and ⌘L.
diff --git a/packages/app/src/components/BottomComposer.tsx b/packages/app/src/components/BottomComposer.tsx
index e31f5134a..d96f02c31 100644
--- a/packages/app/src/components/BottomComposer.tsx
+++ b/packages/app/src/components/BottomComposer.tsx
@@ -76,6 +76,7 @@ import { cn } from '@/lib/utils';
import { docNameToRelativePath } from '@/lib/workspace-paths';
import { emitOpenAskAiComposer, subscribeToOpenAskAiComposer } from './ask-ai-composer-events';
import { clearComposerDraft, getComposerDraft, setComposerDraftDoc } from './composer-draft-store';
+import { focusComposerInputOnCardPointer } from './focus-composer-on-card-pointer';
import { usePageList } from './PageListContext';
// Each suggestion holds long enough to read, then cross-fades to the next.
@@ -702,9 +703,15 @@ export function BottomComposer({
// the card stacks its children vertically. The card markup is mode-agnostic;
// only the outer host wrapper (overlay vs in-flow) differs below.
const card = (
+ // biome-ignore lint/a11y/noStaticElementInteractions: pointer clicks only delegate focus to the composer's editable; keyboard users focus it directly (Tab / ⌘L).
<div
ref={cardRef}
- className="pointer-events-auto group relative flex flex-col gap-1.5 rounded-2xl border border-border/60 bg-card px-3 py-2 shadow-sm transition-colors focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50"
+ // Click anywhere in the card's whitespace (padding, row gaps, the space
+ // beside the short single-line input) focuses the field — the standard
+ // chat-composer affordance. Presses on the send button / chips / editable
+ // are left alone. See focus-composer-on-card-pointer.ts.
+ onMouseDown={(event) => focusComposerInputOnCardPointer(event, inputRef)}
+ className="pointer-events-auto group relative flex cursor-text flex-col gap-1.5 rounded-2xl border border-border/60 bg-card px-3 py-2 shadow-sm transition-colors focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50"
>
{/* Collapse handle — a small tab centered above the card's top edge,
revealed on hover/focus. Collapses the composer to the footer tab. Doc
diff --git a/packages/app/src/components/empty-state/CreatePromptComposer.tsx b/packages/app/src/components/empty-state/CreatePromptComposer.tsx
index 62e6bb6a3..4835bde68 100644
--- a/packages/app/src/components/empty-state/CreatePromptComposer.tsx
+++ b/packages/app/src/components/empty-state/CreatePromptComposer.tsx
@@ -11,6 +11,7 @@ import {
type CreateScenario,
useCreateSuggestions,
} from '@/components/empty-state/use-create-suggestions';
+import { focusComposerInputOnCardPointer } from '@/components/focus-composer-on-card-pointer';
import { TargetIcon } from '@/components/handoff/OpenInAgentMenuItem';
import { useTerminalLaunch } from '@/components/handoff/TerminalLaunchContext';
import { cliIconTargetId, VISIBLE_CLIS } from '@/components/handoff/terminal-cli-display';
@@ -291,7 +292,15 @@ export function CreatePromptComposer({ scenario, className }: CreatePromptCompos
return (
<div className={cn('flex w-full flex-col gap-3', className)}>
- <div className="flex w-full flex-col rounded-2xl border border-border/60 bg-card shadow-sm transition-colors focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50">
+ {/* biome-ignore lint/a11y/noStaticElementInteractions: pointer clicks only delegate focus to the composer's editable; keyboard users focus it directly (Tab / ⌘L). */}
+ <div
+ // Click anywhere in the card's whitespace (the padding around the input,
+ // the footer row beside the Create button) focuses the field — the
+ // standard chat-composer affordance. Presses on the Create split button /
+ // chips / editable are left alone. See focus-composer-on-card-pointer.ts.
+ onMouseDown={(event) => focusComposerInputOnCardPointer(event, inputRef)}
+ className="flex w-full cursor-text flex-col rounded-2xl border border-border/60 bg-card shadow-sm transition-colors focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50"
+ >
{/* The card owns the border + focus ring; the mention input is bare (no
border/ring of its own) so the whole card lights up on focus instead
of nesting a second outline. The `@`-typeahead reuses the workspace
diff --git a/packages/app/src/components/focus-composer-on-card-pointer.ts b/packages/app/src/components/focus-composer-on-card-pointer.ts
new file mode 100644
index 000000000..240556d00
--- /dev/null
+++ b/packages/app/src/components/focus-composer-on-card-pointer.ts
@@ -0,0 +1,46 @@
+/**
+ * Shared "click the card, focus the field" affordance for the two Ask AI
+ * composers (the bottom docked composer and the empty-state create composer).
+ *
+ * Both wrap a ProseMirror `contentEditable` (`ComposerMentionInput`), not a
+ * native `<input>`/`<textarea>`. A contentEditable focuses on click only within
+ * its OWN box, and — unlike a labelable form control — a wrapping `<label>`
+ * cannot forward a click into it (CSS/HTML can't move focus into a
+ * contentEditable). So the standard chat-composer affordance (ChatGPT / Claude /
+ * Cursor: click anywhere in the field's card to focus the input) needs this
+ * pointer handler on the card.
+ *
+ * a11y: this is a pointer-only progressive enhancement. The card keeps passive
+ * semantics (no `role`/`tabindex`) — the real control is the inner textbox,
+ * which keyboard + AT users already reach via Tab and the ⌘L shortcut — so it
+ * adds no interactive markup to announce and no tab-order change.
+ */
+
+import type { RefObject } from 'react';
+import type { ComposerMentionInputHandle } from '@/editor/ComposerMentionInput';
+
+// Interactive descendants that own their own click: real buttons/links, menu
+// items, native form fields, and the editable itself (let the browser place the
+// caret there natively). A click landing on any of these is left alone.
+const INTERACTIVE_TARGET_SELECTOR =
+ 'button, a[href], [role="menuitem"], [role="button"], input, textarea, select, [contenteditable="true"]';
+
+/**
+ * `onMouseDown` handler for a composer card: when the press lands on the card's
+ * non-interactive whitespace (its padding, the row gaps, the empty space beside
+ * a short single-line input), focus the field instead of letting focus fall to
+ * `<body>`. Presses on a control or inside the editable are left untouched.
+ *
+ * Uses `mousedown` (not `click`) and `preventDefault` so focus never visibly
+ * bounces to the card first, and no text-selection drag starts on the padding.
+ */
+export function focusComposerInputOnCardPointer(
+ event: { target: EventTarget | null; preventDefault: () => void },
+ inputRef: RefObject<ComposerMentionInputHandle | null>,
+): void {
+ if (!(event.target instanceof HTMLElement) || event.target.closest(INTERACTIVE_TARGET_SELECTOR)) {
+ return;
+ }
+ event.preventDefault();
+ inputRef.current?.focus();
+}