Skip to content
kitn AI/UI

Prompt Input

kai-prompt-input

A Shadow DOM chat composer — auto-resizing textarea, send button, suggestion chips, attachments, and an extensible toolbar. Drop it into any framework without style conflicts.

  • Shadow DOM
  • 8 events
  • Uncontrolled by default
  • Starter suggestions
  • Slash-command palette
  • Custom toolbar buttons
  • Pre-seeded attachments

Register elements once, then wire up JS properties and DOM events:

<kai-prompt-input id="input" style="display:block; width:100%;"></kai-prompt-input>
<script type="module">
import '@kitn.ai/ui/elements';
const input = document.getElementById('input');
input.suggestions = ['Summarize this thread', 'Draft a reply'];
input.slashCommands = [
{ id: 'summarize', label: '/summarize', description: 'Summarize', category: 'Actions' },
];
input.addEventListener('kai-submit', (e) => console.log('send:', e.detail.value, e.detail.attachments));
input.addEventListener('kai-value-change', (e) => console.log('typing:', e.detail.value));
</script>
  • Array propssuggestions, slashCommands, slashActiveIds, and attachments are arrays, so set them in JavaScript rather than as HTML attributes.
  • Scalar flagsplaceholder, disabled, loading, search, voice, stoppable, slashCompact, and suggestionMode work as plain attributes or properties.
  • Loading + stoppable — set loading while a response streams; add stoppable to swap the send button for a Stop button that fires kai-stop.
  • Custom toolbar buttons — place <kai-action id icon tooltip> children inside the element; clicks fire kai-toolbar-action with detail.action.

Out-of-the-box composer with starter suggestions. Type and press Enter (or click a chip) to fire kai-submit.

search and voice flags add Globe and Mic buttons to the toolbar, firing kai-search and kai-voice respectively.

Set slashCommands to enable the palette. Typing / opens it; selecting an entry fires kai-slash-select. Use slashActiveIds to highlight active commands.

Set attachments to pre-populate staged files. The element manages attachment state — the paperclip adds more, each chip has a remove button.

loading blocks submit while a response streams. stoppable swaps send for a Stop button that fires kai-stop.

disabled makes the composer entirely non-interactive — useful for read-only or locked states.

PropertyTypeDefaultNotes
value Controlled value of the input. When set, the host owns the text and must update it on `kai-value-change`; leave unset for uncontrolled behavior.
placeholder 'Send a message...' Placeholder text shown in the empty input.
disabled false Disable the input and submit button entirely (non-interactive).
loading false Show the loading/streaming state and block submit (use while awaiting a reply).
suggestions Starter prompts shown above the input. Clicking one follows `suggestionMode`. Set as a JS property.
suggestionMode 'submit' What clicking a suggestion does: `'submit'` (default) sends it immediately as if typed and submitted; `'fill'` just places it in the input.
slashCommands Slash commands — when set, typing `/` opens the command palette. Set as a JS property.
slashActiveIds Command ids to highlight as active.
slashCompact false Single-line palette rows.
search false Show a Search (Globe) button in the left toolbar; clicking it fires a `search` event.
voice false Show a Voice (Mic) button in the left toolbar; clicking it fires a `voice` event.
stoppable false When set and `loading` is true, the send button is replaced by a Stop button (square icon, "Stop" aria-label). Clicking it fires `kai-stop`.
attachments Attachments to seed the input with (so a consumer can pre-populate staged files without an upload). Set as a JS property; the element then manages its own attachment state from there (add via the paperclip, remove per chip).
EventDetailNotes
Record<string, never> The Search (Globe) toolbar button was clicked.
A slash command was chosen from the palette.
Record<string, never> The Stop button was clicked while `stoppable` and `loading` are both true.
The user submitted the prompt (Enter or send button) with its attachments.
A suggestion was clicked while `suggestion-mode="fill"`.
A custom `<kai-action>` toolbar button was clicked. `action` is the `id` of the `<kai-action>` element that was clicked.
The input text changed (fires on every keystroke).
Record<string, never> The Voice (Mic) toolbar button was clicked.