YuhuanStudioYunUIDocs
Chat

Chat Composer

A controlled, auto-growing input with Enter-to-send, attachment/toolbar slots and optional host-fed source, command and model menus.

A controlled chat composer with an auto-growing textarea, Enter-to-send (Shift+Enter for a newline), a send/stop button, and host-owned attachment and toolbar slots. The host may also provide source items for @ mentions, commands for /, and a grouped model list. These menus render only from the supplied data; YunUI does not upload files, search sources, run commands, or call a model. The host owns the selected ids and callbacks.

Import

tsx1 line
import { ChatComposer } from "@yuhuanowo/yunui/chat";

Example

Use @ or / to filter the host-provided source or command fixtures, or open the model menu. This docs preview records callbacks locally and sends no request.

ChatComposer

Menus use fixture data supplied by this docs host.

Workspace docs

Usage

tsx33 linesScroll horizontally
import {
ChatComposer,
type ChatComposerCommand,
type ChatComposerMenuItem,
type ChatComposerModel,
} from "@yuhuanowo/yunui/chat";

const [value, setValue] = useState("");

The @ picker toggles stable source ids. / commands insert text only when the host supplies insertText; selecting a semantic command without insertion text is handled by onCommandSelect. Model data and selection are also host-controlled. Omit a menu's item prop to omit that menu. Supplying items without the corresponding change callback leaves its choices disabled. Use labels.prompt to override the textarea's accessible name, along with the menu labels and empty-state copy.

Compatibility: existing value, onChange, onSend, onStop, loading, attachment, and toolbar props keep their behavior. Legacy sendLabel and stopLabel remain accepted; when both an old prop and labels.send / labels.stop are provided, labels takes precedence.

Props

PropTypeDefaultDescription
allowSendEmptybooleanfalseAllow sending with empty text — e.g. when attachments alone make a valid message.
attachmentsReactNode—Attachment chips / previews, rendered above the textarea. The host owns the content and its actions.
classNamestring—
commandItemsreadonly ChatComposerCommand[]—Optional host-owned command list. Commands never infer insertion text from an id or label.
disabledbooleanfalse
labelsChatComposerLabels—Accessible names and menu copy. Existing send/stop overrides remain supported.
loadingbooleanfalse
maxRowsnumber8Max rows before the textarea scrolls.
modelItemsreadonly ChatComposerModel[]—Optional host-owned model list. Supplying `[]` renders the localized empty state.
onChange*(value: string) => void—
onCommandSelect((item: ChatComposerCommand) => void)—Host callback for semantic command selection.
onModelChange((id: string) => void)—Host callback for model selection. Without it, model options are disabled.
onSend*() => void—Called when the user sends (Enter or the send button).
onSourceToggle((id: string, selected: boolean) => void)—Host callback for selecting or removing a source. The second argument is the desired selected state.
onStop(() => void)—Called when the stop button is pressed while `loading`.
placeholderstringSend a message…
selectedModelIdstring—Host-owned selected model id.
selectedSourceIdsreadonly string[][]Host-owned selected source ids, used for chips and menu selection state.
sendDisabledbooleanfalseForce-disable the send button even with text (e.g. invalid state).
sendLabelstring—@deprecated Use labels.send. Retained for 0.2.17 compatibility.
sourceItemsreadonly ChatComposerMenuItem[]—Optional host-owned source list. Supplying `[]` renders the localized empty state.
stopLabelstring—@deprecated Use labels.stop. Retained for 0.2.17 compatibility.
toolbarReactNode—Left-aligned host toolbar (attach, mode, feature toggles, …).
value*string—

On this page