Skip to content

Ghost Text

Inline AI completion in a text field or textarea. The suggestion shows as faint text after the caret, lined up with the real text across lines. Tab accepts it, Ctrl/Cmd + Right Arrow takes one word, Esc dismisses it, and typing the same characters consumes it.

On this page
Used for
  • Inline AI completion
  • Autocomplete a prompt
  • Suggest the next words
  • Code-like completion
  • Tab to accept

Examples

Installation

npx knowns-ui@latest add ghost-text
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

Props

value / onChange
string / (value) => void
The field's text. Ghost Text is controlled.
suggestion
string | null
The completion for the text as it is now. Typing the same characters consumes it; typing anything else hides it until the next one.
loading
boolean
Defaultfalse
A suggestion is on its way: a faint shimmer after the caret, and aria-busy on the field.
onAccept
(text, kind: "all" | "word") => void
Called with what was accepted: the rest (Tab) or the next word (Ctrl/Cmd + Right Arrow).
onDismiss
() => void
Esc hid the suggestion. It stays hidden until a new suggestion arrives.
multiline
boolean
Defaultfalse
A textarea. The ghost wraps with the text, line for line.
rows
number
Default3
Textarea rows.
variant
"default" | "mono"
Default"default"
Mono is for code: monospace, tab size 2, no spellcheck.
showHint
boolean
Defaulttrue
A small Tab key at the end of the field while a suggestion shows.
placeholder, disabled, id, name, autoFocus, aria-*
-
Passed to the input or textarea. aria-describedby is merged with the built-in hint.
fieldClassName / className
string
On the input or textarea / on the wrapper.

Accessibility

  • The suggestion lives in a mirror layer marked aria-hidden. Screen readers get it through aria-describedby: “Suggestion: … Press Tab to accept”.
  • A polite live region says once that a suggestion is available. It doesn't repeat on every keystroke.
  • Tab, Ctrl/Cmd + Right Arrow and Esc are only captured while a suggestion is visible. Otherwise Tab moves focus as usual.
  • The field never loses focus, and the ghost only shows with the caret at the end of the text.
  • With reduced motion, the shimmer and the fade-in are off.

What it handles

  1. 01Shows the suggestion prop in faint text right after the caret, lined up with the real text by a mirror layer.
  2. 02Accepts the whole rest with Tab and one word at a time with Ctrl or Cmd plus Right Arrow when the caret is at the end, and reports the text through onAccept.
  3. 03Hides the suggestion with Escape and calls onDismiss until the next one arrives.
  4. 04Consumes the ghost as you type the same characters, and drops it when you type anything else or delete past where it began.
  5. 05Shows a faint shimmer after the caret while loading is true, and a Tab key hint at the field end while a suggestion is visible and focused.
  6. 06Works on an input or, with multiline and rows, a textarea, and variant="mono" gives code-like text with tab size 2.

States

First render
Nothing. It paints as it is
none
A suggestion arrives
The ghost text fades in
180ms, ease out
Tab key hint
The hint fades in and out with focus
180ms, ease out
Loading
A shimmer sweeps after the caret
none
Accept or dismiss
The ghost goes at once
none
Reduced motion
No fade and no sweep
0ms

Works with

When to use

When to use

  • Inline AI completion in a prompt box, a reply field or a code-like textarea.
  • Suggestions the user takes with Tab, one word at a time, or ignores by typing on.

When not to use

  • A full chat input with attachments and a send button: use Chat Composer.
  • Picking from a list of known values: use Combobox.

Using with AI

Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:

  • Add the Knowns UI Ghost Text to my app and wire it to my own data.
  • I need inline AI completion in a prompt box, a reply field or a code-like textarea. Set that up with the Knowns UI Ghost Text.
  • Which Ghost Text props do I need for a minimal setup? Show me a short example.

With the server connected, your assistant calls get_component({ name: "ghost-text" }) and search_docs({ query: "ghost text" }).

Need help?

Stuck on Ghost Text, or found something off? We read every message.