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.
- Inline AI completion
- Autocomplete a prompt
- Suggest the next words
- Code-like completion
- Tab to accept
Examples
Installation
npx knowns-ui@latest add ghost-textPaste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install Ghost text from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/ghost-text
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add ghost-text
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- components/ui/knowns/kbd.tsx
- components/ui/knowns/field-class.ts
- components/ui/knowns/textarea.tsx
- components/ui/knowns/chat-composer/use-autosize.ts
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/use-floating.ts
- components/ui/knowns/tooltip.tsx
- components/ui/knowns/tooltip-utils.ts
- components/ui/knowns/input.tsx
- components/ui/knowns/ghost-text/ghost-text.tsx
- components/ui/knowns/ghost-text/ghost-utils.ts
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/ghost-text, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "ghost-text" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.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- Default
false - 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- Default
false - A textarea. The ghost wraps with the text, line for line.
- rows
number- Default
3 - Textarea rows.
- variant
"default"|"mono"- Default
"default" - Mono is for code: monospace, tab size 2, no spellcheck.
- showHint
boolean- Default
true - 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.
| Prop | Type | Default | Description |
|---|---|---|---|
| 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 | false | 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 | false | A textarea. The ghost wraps with the text, line for line. |
| rows | number | 3 | Textarea rows. |
| variant | "default" | "mono" | "default" | Mono is for code: monospace, tab size 2, no spellcheck. |
| showHint | boolean | true | 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
- 01Shows the suggestion prop in faint text right after the caret, lined up with the real text by a mirror layer.
- 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.
- 03Hides the suggestion with Escape and calls onDismiss until the next one arrives.
- 04Consumes the ghost as you type the same characters, and drops it when you type anything else or delete past where it began.
- 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.
- 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
| State | What moves | Timing |
|---|---|---|
| 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" }).