Back to Copilotkit

CopilotChatInput

examples/v2/docs/reference/copilot-chat-input.mdx

1.57.07.9 KB
Original Source

CopilotChatInput is the default input component used by CopilotChat. It provides a full-featured text input with support for voice transcription, slash commands, and customizable toolbar buttons.

What is CopilotChatInput?

The CopilotChatInput component:

  • Provides a rich text input with auto-expanding height
  • Supports voice transcription via microphone button
  • Includes a slash command menu for quick actions
  • Shows a tools/add menu button for file uploads and custom actions
  • Handles send and stop functionality during streaming
  • Built on the slot system for deep customization

Component Architecture

CopilotChatInput provides slots for customizing each part of the input:

mermaid
graph LR
    Input[CopilotChatInput] --> textArea
    Input --> sendButton
    Input --> startTranscribeButton
    Input --> cancelTranscribeButton
    Input --> finishTranscribeButton
    Input --> addMenuButton
    Input --> audioRecorder
    Input --> disclaimer

Slot Descriptions

SlotDescription
textAreaThe main textarea input element
sendButtonSend message or stop generation button
startTranscribeButtonButton to start voice recording
cancelTranscribeButtonButton to cancel voice recording
finishTranscribeButtonButton to finish voice recording
addMenuButtonPlus button for file uploads and tools menu
audioRecorderVoice recording visualization component
disclaimerDisclaimer text shown below the input

Basic Usage

Customize the input through the input prop on CopilotChat:

tsx
<CopilotChat
  input={{
    className: "border-2 border-blue-200 rounded-xl",
    sendButton: "bg-blue-500 hover:bg-blue-600",
  }}
/>

Input Modes

CopilotChatInput operates in three modes:

ModeDescription
inputNormal text input mode (default)
transcribeVoice recording mode
processingShows loading spinner while transcribing

The component automatically switches between modes based on user interaction with the transcription buttons.

Slot Customization

CopilotChatInput uses the slot system. Each slot accepts four types of values:

  1. Tailwind class string - Add or override CSS classes
  2. Props object - Pass additional props to the default component
  3. Custom component - Replace the component entirely
  4. Nested sub-slots - Drill down to customize child components

TextArea Customization

The textArea slot controls the main text input:

tsx
<CopilotChat
  input={{
    textArea: {
      className: "text-lg font-medium",
      placeholder: "What's on your mind?",
    },
  }}
/>

Send Button Customization

The sendButton slot controls the send/stop button:

tsx
<CopilotChat
  input={{
    sendButton: "bg-green-500 hover:bg-green-600 text-white",
  }}
/>

Or with a custom component:

tsx
function CustomSendButton({ onClick, disabled, children }) {
  return (
    <button
      onClick={onClick}
      disabled={disabled}
      className="px-4 py-2 bg-gradient-to-r from-blue-500 to-purple-500 text-white rounded-lg"
    >
      {children}
    </button>
  );
}

<CopilotChat
  input={{
    sendButton: CustomSendButton,
  }}
/>;

Transcription Buttons

Customize the voice transcription buttons:

tsx
<CopilotChat
  input={{
    startTranscribeButton: "text-blue-500",
    cancelTranscribeButton: "text-red-500",
    finishTranscribeButton: "text-green-500",
  }}
/>

Add Menu Button

The add menu button shows a dropdown with file upload and custom tool options:

tsx
<CopilotChat
  input={{
    addMenuButton: "text-gray-500 hover:text-gray-700",
  }}
/>

Disclaimer Customization

The disclaimer slot shows helper text below the input:

tsx
<CopilotChat
  input={{
    disclaimer: "text-xs text-gray-400 italic",
  }}
/>

To hide the disclaimer entirely:

tsx
<CopilotChat
  input={{
    disclaimer: () => null,
  }}
/>

Replacing the Component

To completely replace the input with your own component:

tsx
import { CopilotChatInput } from "@copilotkit/react-core";

function CustomInput({ onSubmitMessage, isRunning, onStop, ...props }) {
  return (
    <div className="custom-input-wrapper">
      <CopilotChatInput
        onSubmitMessage={onSubmitMessage}
        isRunning={isRunning}
        onStop={onStop}
        textArea="bg-gray-50"
        sendButton="bg-blue-600"
        {...props}
      />
    </div>
  );
}

<CopilotChat input={CustomInput} />;

Using the Render Function

For full control, use the children render function pattern:

tsx
function CustomInput(props) {
  return (
    <CopilotChatInput {...props}>
      {({ textArea, sendButton, addMenuButton }) => (
        <div className="flex items-center gap-2 p-4 bg-gray-100 rounded-xl">
          {addMenuButton}
          <div className="flex-1">{textArea}</div>
          {sendButton}
        </div>
      )}
    </CopilotChatInput>
  );
}

<CopilotChat input={CustomInput} />;

The render function receives:

PropertyTypeDescription
textAreaReactElementThe bound textarea component
sendButtonReactElementThe bound send/stop button
startTranscribeButtonReactElementStart recording button
cancelTranscribeButtonReactElementCancel recording button
finishTranscribeButtonReactElementFinish recording button
addMenuButtonReactElementThe tools menu button
audioRecorderReactElementVoice recording visualization
disclaimerReactElementThe disclaimer text
mode'input' | 'transcribe' | 'processing'Current input mode
isRunningbooleanWhether AI is generating

Keyboard Shortcuts

ShortcutAction
EnterSend message (or stop if generating)
Shift+EnterInsert newline
/Open slash command menu
EscapeClose slash command menu
↑/↓Navigate slash menu items

Examples

Custom Styled Input

tsx
<CopilotChat
  input={{
    className: "shadow-lg",
    textArea: "text-base placeholder:text-gray-400",
    sendButton: "bg-indigo-600 hover:bg-indigo-700",
    addMenuButton: "text-indigo-600",
  }}
/>

Hiding the Disclaimer

tsx
<CopilotChat
  input={{
    disclaimer: () => null,
  }}
/>

Custom Disclaimer Text

Use labels to customize the disclaimer text:

tsx
<CopilotChat
  labels={{
    chatDisclaimerText:
      "AI responses may contain errors. Always verify important information.",
  }}
/>

Hide Transcription Button

tsx
<CopilotChat
  input={{
    startTranscribeButton: () => null,
  }}
/>