Axon 911 Frontend DocsAxon 911 Frontend Docs
Axon 911 Frontend Docs
    Loading navigation…
U
User
Switch to light mode
  1. Components
  2. Chat Input
  3. API and Development

Chat Input

API and Development

View SourceOpens in a new tabSubmit IssueOpens in a new tab
Import ChatInput, ChatInputLayout, hasSendableText from @prepared911/ui/chat-input. The root is a div that takes id, className, ref and data-* attributes (reserved design-system state names are dropped). Every other prop is named below. There is no style, no children, and no other native attribute.
Sending
PropTypeDefaultNotes
onSend(message: string, segments: readonly ChatInputSegment[], details: ChangeDetails<FormSubmit>) => voidrequiredmessage is the trimmed text with each inline chip as @label; segments is the same content in order. Not called for empty text, while composing, while a response generates, or when the composer is disabled or read-only. details.cancel() keeps the text
sendLabelLocalizedMessagerequiredName of Send at rest
sendPendingLabelLocalizedMessagerequiredName of Send while pending
sendDisabledAnnouncementLocalizedMessageAnnounced when the text is emptied and when Enter is pressed in an empty composer
statusChatInputStatus: the values of ChatStatus from ai"ready"While "submitted" or "streaming" a send is blocked and Send becomes Stop (with onStop) or pending
onStop, stopLabel() => void, LocalizedMessageBoth or neither
Text
PropTypeDefaultNotes
valuestringControlled text, each inline chip as @label. Pass "" for empty
defaultValuestring""Uncontrolled start
onValueChange(value: string, details: ChangeDetails<InputChange | ImperativeAction | FormSubmit>) => voidEvery change, including the clear after a send. An edit has already happened, so it is not cancelable
placeholderLocalizedMessageCopy while empty
aria-label, aria-labelledby, aria-describedbyLocalizedMessage, string, stringName and description of the typed area
aria-invalidbooleanDraws the strong edge
disabled, readOnlybooleanfalse
sizeInputSizeLargeHeight of the buttons and of one line: 24, 28, 32px
layoutChatInputLayoutReflowReflow or Stacked
Parts
PropTypeNotes
attach, addLabelreadonly ChatInputAttachItem[], LocalizedMessageRows of the attach menu behind the add control, and its name. Both or neither
chips, chipsLabelreadonly ChatInputChip[], LocalizedMessageContext chips in a row above the typed area, and the row's name
onChipDismiss(id: string, details: ChangeDetails<ItemPress | InputChange>) => voidRemoves context chips (without it they have no remove control) and reports every inline chip that leaves the text: ItemPress for the remove control, which is cancelable, and InputChange for Backspace, Delete, cut and undo, which is not
suggestions, suggestionsLabelreadonly ChatInputChip[], LocalizedMessageQuick actions under the surface
onSuggestionClick(id: string) => voidAfter a suggestion is inlined
modeToggle{ label, pressed, onPressedChange }A toggle before Send
A ChatInputChip is { id, label, icon?, removeLabel, removedAnnouncement }. A ChatInputAttachItem is { id, label, icon?, onSelect, separatorBefore? }.
Refs
PropTypeNotes
refRef<HTMLDivElement>The root
inputRefRef<HTMLDivElement>The typed area, the textbox
handleRefRef<ChatInputHandle>insertChip(chip) and focus(). With no caret in the typed area, insertChip adds the chip at the end of the content, on its last line
Exports
ChatInput, ChatInputLayout, hasSendableText, and the types ChatInputProps, ChatInputChip, ChatInputAttachItem, ChatInputModeToggle, ChatInputSuggestion, ChatInputHandle, ChatInputSegment, ChatInputTextSegment, ChatInputChipSegment, ChatInputStatus, ChatInputSendDetails, ChatInputValueChangeDetails, ChatInputChipDismissDetails, ChatInputElement, ChatInputSendReason, ChatInputValueChangeReason and ChatInputChipDismissReason.
Props
NameTypeDefaultDescription
onSend(message: string, segments: readonly ChatInputSegment[], details: ChatInputSendDetails) => void—Called when Enter or Send asks to send. It runs only when the message has text other than whitespace, and never while a response is generating, while an input method is composing, or while the composer is disabled or read-only. Shift+Enter inserts a newline instead. message is the typed text trimmed at both ends, with each inline chip written as @label. segments is the same content in order, so inline chips keep their ids. Context chips are never part of either. The text and the inline chips clear after this returns unless details.cancel() is called. A send that can fail should cancel and clear the composer itself once the message is accepted. @param message - The trimmed text @param segments - The trimmed content in order @param details - Change metadata; event is the key or click, and cancel() keeps the text
sendLabelLocalizedMessage—Accessible name of the Send control at rest, such as "Send message". It is never drawn.
sendPendingLabelLocalizedMessage—Accessible name of the Send control while a response is "submitted" or "streaming" and there is no Stop, such as "Sending message".
addLabelLocalizedMessage—Accessible name of the add control, such as "Add". It is never drawn.
aria-describedbystring—Id of the element that describes the typed area.
aria-invalidboolean—Marks the typed area invalid and draws the strong edge.
aria-labelLocalizedMessage—Accessible name of the typed area. The composer draws no visible label.
aria-labelledbystring—Id of the element that names the typed area.
attachreadonly ChatInputAttachItem[]—Rows of the attach menu, in order. An empty array shows no add control. Not allowed without addLabel.
chipsreadonly ChatInputChip[]—Persistent context chips in a row above the typed area. They survive a send and are never part of the sent message. Pass the full set on every render; the row mirrors it. An empty array draws no row.
chipsLabelLocalizedMessage—Names the row of context chips, such as "Context".
classNamestring—Classes appended after the generated classes. Put overrides in @layer chroma.overrides.
data-alignundefined——
data-checkedundefined——
data-copy-statusundefined——
data-dirtyundefined——
data-disabledundefined——
data-draggingundefined——
data-ending-styleundefined——
data-expandedundefined——
data-filledundefined——
data-focus-visibleundefined——
data-focusedundefined——
data-highlightedundefined——
data-hoveredundefined——
data-indeterminateundefined——
data-instantundefined——
data-invalidundefined——
data-is-newundefined——
data-loadingundefined——
data-nestedundefined——
data-openundefined——
data-orientationundefined——
data-overflowundefined——
data-placeholderundefined——
data-popup-openundefined——
data-pressedundefined——
data-readonlyundefined——
data-requiredundefined——
data-scrollingundefined——
data-selectedundefined——
data-sideundefined——
data-starting-styleundefined——
data-touchedundefined——
data-validundefined——
defaultValuestring—Initial text when uncontrolled.
disabledboolean—Disables the typed area and every control.
handleRefRef<ChatInputHandle>—Imperative handle for inserting chips.
idstring—Element id of the root.
inputRefRef<HTMLDivElement>—Ref to the typed area, the element with the textbox role, such as to focus it when a drawer opens.
layoutChatInputLayoutChatInputLayout.ReflowHow the controls sit relative to the typed area.
modeToggleChatInputModeToggle—A binary mode shown before the trailing control.
onChipDismiss((id: string, details: ChatInputChipDismissDetails) => void)—Called when a context chip is removed with its control, and when an inline chip leaves the text, whether by its control, Backspace, a cut or an undo. Without it context chips are drawn with no remove control. A context chip belongs to the parent, which removes it from chips. Calling details.cancel() on a removal with the control keeps an inline chip. @param id - The id of the chip @param details - Change metadata; reason is ItemPress for the control and InputChange for an edit
onStop(() => void)—Not allowed without stopLabel. Stops an in-flight response. While status is "submitted" or "streaming" the trailing control becomes Stop.
onSuggestionClick((id: string) => void)—Called with the id of a suggestion after it is inlined. The composer already did the work; this is for reacting to it.
onValueChange((value: string, details: ChatInputValueChangeDetails) => void)—Called for every change of the text: a keystroke, paste or drop, an inline chip added or removed, and the clear after a send. The typed area has already changed when this runs, so an edit cannot be canceled. A controlled parent stores the value here; a value that differs from the last one reported replaces the typed area with plain text and removes its inline chips. @param value - The text, with each inline chip written as @label @param details - Change metadata
placeholderLocalizedMessage—Placeholder copy while the typed area is empty.
readOnlyboolean—The typed area can be read and focused but not edited, and nothing is sent.
refRef<HTMLDivElement>—Ref to the root div.
sendDisabledAnnouncementLocalizedMessage—Announced politely when there is nothing to send: when the person empties the text, and when they press Enter in an empty composer. Say why Send is unavailable, such as "Nothing to send". Not announced after a send.
sizeInputSize—Control scale: the height of the buttons and of one line. Defaults to {@link InputSize.Large}.
statusChatInputStatus"ready"Status of the send, the AI SDK's ChatStatus. While "submitted" or "streaming" a send is blocked, and the trailing control becomes Stop when onStop is set, else Send in its pending state.
stopLabelLocalizedMessage—Accessible name of the Stop control, such as "Stop generating".
suggestionsreadonly ChatInputChip[]—Quick actions under the surface. A chosen one moves into the text as a chip and leaves the row; it returns when the chip does.
suggestionsLabelLocalizedMessage—Names the list of suggestions, such as "Suggestions".
valuestring—Controlled text, with each inline chip written as @label. undefined on the first render is uncontrolled. Pass "" for a controlled empty value.
Storybook
Interactive examples and edge cases for this component are in Storybook.
DefaultOpens in a new tab
Previous
Chat Input / Usage
Next
Chat Input / Accessibility
On this page
Sending
Text
Parts
Refs
Exports
Props
Storybook