Components

ChatComposer

Compound component for composing and submitting chat messages with auto-resizing input.

Category: AI / Chat / Composite

Import

import {
  ChatComposer,
  ChatComposerInput,
  ChatComposerActions,
  ChatComposerSend,
} from "@hareru/ui"

Exports

NameTypeDescription
ChatComposerComponentRoot <form> element
ChatComposerInputComponentAuto-resizing <textarea>
ChatComposerActionsComponentExtra action buttons container
ChatComposerSendComponentSubmit button with default send icon
ChatComposerPropsTypeProps for ChatComposer
ChatComposerInputPropsTypeProps for ChatComposerInput
ChatComposerActionsPropsTypeProps for ChatComposerActions
ChatComposerSendPropsTypeProps for ChatComposerSend

Key Props

ChatComposer

PropTypeDefaultDescription
disabledbooleanfalseDisables the composer
onSubmitFormEventHandlerForm submit handler (default behavior is prevented)

ChatComposerInput

PropTypeDefaultDescription
submitOnEnterbooleantrueSubmit on Enter key (Shift+Enter inserts a newline)
onValueChange(value: string) => voidCallback invoked when the value changes

Structure

  • ChatComposerInput [input] (expected)
  • ChatComposerActions [container]
    • ChatComposerSend [action]

(expected) = recommended in canonical composition, not runtime-required.

States

StateTypeValuesDefaultCSS Reflection
disabledbooleanBEM modifier

Accessibility

  • Keyboard:
    • Enter to submit message
    • Shift+Enter for new line
  • Notes: Compose area uses textarea with form submission.

Usage

import { useState, type FormEvent } from "react"
import {
  ChatComposer,
  ChatComposerInput,
  ChatComposerActions,
  ChatComposerSend,
  Button,
} from "@hareru/ui"

function MyChatInput() {
  const [message, setMessage] = useState("")

  const handleSubmit = (e: FormEvent) => {
    if (!message.trim()) return
    console.log("send:", message)
    setMessage("")
  }

  return (
    <ChatComposer onSubmit={handleSubmit}>
      <ChatComposerInput
        value={message}
        onValueChange={setMessage}
        placeholder="Type a message..."
      />
      <ChatComposerActions>
        <Button variant="ghost" size="icon">Attach</Button>
      </ChatComposerActions>
      <ChatComposerSend />
    </ChatComposer>
  )
}

Notes

  • ChatComposerInput auto-resizes its height as the user types.
  • When submitOnEnter is true, pressing Enter submits the form. Shift+Enter inserts a newline. IME composition is handled correctly.
  • ChatComposerSend renders a default send icon SVG if no children are provided.
  • The composer renders as a <form> element — preventDefault is called automatically on submit.

On this page