Skip to content

Add PromptInput #102

Closed
Closed

Description

@pratikbuilds

Add the core message box: a controlled textarea with highlighted @mention and /command tokens, keyboard-driven suggestions, and a submit button that turns into Stop while the agent replies. The toolbar comes next (#103).

Part of #94.

Why

The message box is where people talk to agents. It has to keep native editing, undo and IME behaviour while still highlighting tokens, and it must never hold the draft itself: the text belongs to the host.

What

  • src/ui/prompt-input.tsx: PromptInput (value, onValueChange, onSubmit), PromptInputTextarea, PromptInputSuggestions, PromptInputSuggestion, PromptInputSubmit (status, onStop).
  • src/lib/prompt-tokens.ts: find the @ or / token at the caret, and split text into highlighted segments.
  • src/hooks/use-prompt-input.ts: active token, suggestion index, key handling.
  • stories/chat/prompt-input.stories.tsx: plain, suggestions open, replying.
  • e2e/fixtures.tsx: a prompt-input scenario that records submits, with e2e/prompt-input.spec.ts.
  • Unit tests beside the lib module and the hook; exports in src/index.ts.

Technique

  • Highlighting: a native <textarea> with transparent text over an aria-hidden mirror <div> that renders the same text with tokens highlighted. The mirror copies the textarea's font, padding, wrapping and scroll position. No contenteditable.
  • Sizing: field-sizing: content where CSS.supports("field-sizing", "content"); elsewhere a measured fallback that sets the height from scrollHeight up to the max. The fallback is a distinct, separately tested piece.

Requirements

  • R29: fully controlled; every feature is opt-in by including its part.
  • R30: overlay mirror with scroll kept in sync; field-sizing with a measured fallback; never submits during IME composition.
  • R31: suggestions driven from the keyboard through usePromptInput; Send turns into Stop while busy.
  • R5–R12: the shared component rules.

Constraints

Done when

  • Unit tests cover:
    • Tokens: the caret inside @ad finds the mention; an email address is not a mention; / counts only at the start of a line.
    • Keys: ArrowDown/ArrowUp wrap, Enter picks, Escape closes, Enter with no list submits, Shift+Enter inserts a newline.
  • Browser spec covers:
    • The mirror's highlighted token sits under the typed token after typing and after scrolling a long draft.
    • Enter during IME composition does not submit.
    • Send becomes Stop while status is streaming and calls onStop.
    • With field-sizing forced off, the textarea grows to its max and then scrolls.
  • No serious or critical axe violation in the new stories, in light or dark.
  • bun run check, bun run build, bun run test:e2e and bun run dep-guard pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions