Composer
The Composer field is a chat-style message input with auto-resize, keyboard submit, file attachments, and quick actions. It works like the message box in Slack or iMessage: the user types a message and presses Enter to send it. It's built for messaging UIs, comment forms, and AI chat interfaces.
Basic Usage
use InertiaUI\Forms\Fields\Composer;
Composer::make('message');This renders a textarea that auto-resizes as the user types, starting at 1 row and growing up to 6. Pressing Enter submits the form, and Shift+Enter adds a newline.
The placeholder method sets the text of the empty textarea:
Composer::make('message')->placeholder('Type your message...');Auto Resize
Auto-resize is enabled by default. The textarea grows as the user types and shrinks when text is removed. To get a fixed-height textarea, disable it:
Composer::make('message')->autoResize(false);Min and Max Rows
You may set the minimum and maximum number of textarea rows:
Composer::make('message')
->minRows(2) // Start at 2 rows
->maxRows(10); // Scroll after 10 rowsKeyboard Submit
The composer submits the form from the keyboard in two ways, and both are enabled by default.
Enter to Submit
By default, pressing Enter submits the form, while Shift+Enter adds a newline. To get a standard textarea experience, disable this:
Composer::make('message')->submitOnEnter(false);Cmd/Ctrl+Enter to Submit
Cmd+Enter or Ctrl+Enter also submits the form by default. You may disable it using the submitOnCmdEnter method:
Composer::make('message')->submitOnCmdEnter(false);File Attachments
The allowAttachments method enables file attachments and adds an attachment button to the composer:
Composer::make('message')->allowAttachments();With attachments disabled, the field submits the message text as a string:
// The submitted request data...
$data = [
'message' => 'Hello',
];With attachments enabled, the same field submits a nested value:
// The submitted request data...
$data = [
'message' => [
'text' => 'Hello',
'attachments' => [
// Temporary upload tokens by default
],
],
];Composer values match the configured attachment mode. Without attachments, the initial value stays a string or null. With attachments enabled, the field always starts from a nested value with text and attachments keys. A scalar becomes the text value, missing keys are filled in, invalid text becomes an empty string, and invalid attachments become an empty array. A hidden conditional Composer resets to the same nested empty value.
Composer attachments use the same upload pipeline as the File field. By default, files upload to a temporary endpoint as soon as they're selected or dropped, and the final form request contains encrypted upload tokens. Laravel keeps those token strings in the request input.
Generated form validation covers the nested message.text, message.attachments, and message.attachments.* paths, and the #[Validate] attribute runs those rules. After validation, read the temporary attachments with $form->uploads('message.attachments'), and use $form->validated(files: false) to mass assign the message data.
A controller that receives a plain Request may use the request-level equivalent, orderedFormUploads('message.attachments'). The request macro hydrates that nested upload key on first read. A FormRequest implementing HasUploads may still opt into eager, rule-driven hydration. See Reading Submitted Uploads.
To receive raw multipart files in the final form request instead of temporary upload tokens, use the storeWithForm method:
Composer::make('message')
->allowAttachments()
->storeWithForm();Since storeWithForm() submits native files, final validation uses normal Laravel file rules on message.attachments.*. Generated form validation applies those rules automatically. A controller that receives a plain Request may validate the same paths itself:
// $request is the current Illuminate\Http\Request...
$request->validate([
'message.text' => ['nullable', 'string'],
'message.attachments' => ['array'],
'message.attachments.*' => [
'file',
'mimetypes:image/png,image/jpeg,application/pdf',
'max:5120',
],
]);To let the user set the submitted file order before sending, enable attachment reordering:
Composer::make('message')
->allowAttachments()
->reorderable();The attachments array follows the displayed order after drag and keyboard reordering.
Upload Options
Composer attachments use the shared File Uploads pipeline. That guide covers temporary uploads, storeWithForm(), custom temporary URLs, named upload routes, chunked(), directToStorage(), upload disks, multipart tuning, upload validators, and token validation.
The frontend packages export ComposerValue and ComposerAttachmentValue for this generated form value.
Spatie Media Library
To let Form::save() persist the message and its attachments together, declare a Media Library collection:
Composer::make('message')
->allowAttachments()
->mediaCollection('message-attachments');The collection accepts the same server-only storage options as a File field:
use InertiaUI\Forms\FileUploads\SubmittedUpload;
use Spatie\MediaLibrary\MediaCollections\FileAdder;
Composer::make('message')
->allowAttachments()
->mediaCollection(
collection: 'message-attachments',
disk: 'media',
responsiveImages: true,
configure: function (FileAdder $adder, SubmittedUpload $upload): void {
$adder->withCustomProperties([
'original_name' => $upload->getUploadedFile()->getClientOriginalName(),
]);
},
);Form::save() applies these options to each new attachment. For applications that own the persistence sequence, the manual upload helpers and MediaLibraryUploads::syncCollection() remain available.
The model must implement Spatie Media Library's HasMedia contract. The Composer attribute needs an array or JSON-compatible cast, because its stored value contains text and durable internal attachment references:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
class Comment extends Model implements HasMedia
{
use InteractsWithMedia;
protected function casts(): array
{
return [
'message' => 'array',
];
}
}Binding resolves those references to the same existing file values the attachment picker uses. Temporary upload tokens and expiring existing file tokens are never written to the model.
The same configuration works on a Composer declared directly inside a Repeater or Blocks schema. All instances of that one schema field share the collection, so unused attachments are only cleaned up after every submitted instance has been considered. Keep the collection exclusive to that field. An absent attachment value leaves the collection untouched, while an explicitly empty value may clear unused media.
Automatic Media Library persistence uses temporary or direct-to-storage upload tokens. Form::save() rejects a Composer that combines mediaCollection() with storeWithForm(). Use the manual upload helpers for native multipart attachments.
Accepted File Types
The acceptedFileTypes method restricts the file types users may select or drop into the composer:
Composer::make('message')
->allowAttachments()
->acceptedFileTypes(['image/png', 'image/jpeg', 'application/pdf']);The values are passed to the native file input's accept attribute, and the Vue and React attachment pickers check them. They also become Laravel mimetypes rules on the real files. Token modes validate them during the upload request, and storeWithForm() validates them on message.attachments.* during final validation. For exact server-side matching, prefer concrete MIME types such as image/png or application/pdf.
Max File Size
The maxFileSize method limits the size of selected attachments in kilobytes:
Composer::make('message')
->allowAttachments()
->maxFileSize(5120); // 5MBVue and React skip files larger than this limit before adding them to the composer. Laravel validates the same max rule during the upload request in token modes, or on each nested file during final validation with storeWithForm().
You may combine these attachment controls to accept only a small set of file types:
Composer::make('message')
->placeholder('Type your message...')
->allowAttachments()
->reorderable()
->acceptedFileTypes(['image/png', 'image/jpeg', 'application/pdf'])
->maxFileSize(5120)
->storeWithForm()
->submitLabel('Send');Character Count and Limit
Show Character Count
The showCharacterCount method displays a character counter below the input:
Composer::make('message')->showCharacterCount();Max Length
The maxLength method sets a character limit for the textarea:
Composer::make('message')
->maxLength(500)
->showCharacterCount();A text-only composer submits a string, and maxLength() also adds a top-level max validation rule for that string.
With attachments enabled, the field submits message as an array with text and attachments. In the generated rules, maxLength() then applies to the nested message.text validation path:
Composer::make('message')
->allowAttachments()
->maxLength(500)
->showCharacterCount();Submit Button
Custom Label
The submitLabel method changes the submit button's text:
Composer::make('message')->submitLabel('Send Message');Loading State
The submit button shows a spinner while the form is processing. To force that loading state, call the loading method:
Composer::make('message')->loading();Quick Actions
Quick actions are preset buttons that replace the composer's text with predefined text, such as canned responses or template messages:
Composer::make('reply')->quickActions([
['label' => 'Thanks!', 'value' => 'Thank you for your message. We will get back to you soon.'],
['label' => 'On it', 'value' => 'We are looking into this and will update you shortly.'],
['label' => 'Resolved', 'value' => 'This issue has been resolved. Please let us know if you need anything else.'],
]);Reply Composer With Attachments
Composer::make('message')
->label('Reply')
->placeholder('Type your message...')
->minRows(2)
->maxRows(8)
->maxLength(2000)
->showCharacterCount()
->allowAttachments()
->reorderable()
->acceptedFileTypes(['image/png', 'image/jpeg', 'application/pdf'])
->maxFileSize(10240)
->submitLabel('Send')
->quickActions([
['label' => 'Thanks', 'value' => 'Thanks for reaching out!'],
])
->required();This example generates nested text and attachment rules, and #[Validate] validates those paths automatically. The upload helpers resolve the temporary upload tokens separately, as described in Reading Submitted Uploads.
All shared field methods remain available. See Form Class, Model Binding, Validation, Conditional Visibility, Authorization, and Styling.
Using the Component Directly
Composer is exported from each stack's components subpath. Vue uses v-model, and React uses a controlled value with onValueChange.
<script setup lang="ts">
import { ref } from 'vue'
import { Composer } from '@inertiaui/form-vue/components'
import type { ComposerAttachment, ComposerAttachmentValue } from '@inertiaui/form-vue'
const message = ref<ComposerAttachmentValue>({
text: '',
attachments: [],
})
const error = ref<string | null>(null)
const sending = ref(false)
const quickActions = [
{ label: 'Thanks', value: 'Thanks for reaching out!' },
{ label: 'On it', value: 'We are looking into this now.' },
]
const fieldParts = {
editor: 'min-h-24',
item: 'bg-zinc-50',
submitButton: 'px-4',
}
function send(value: string, attachments: ComposerAttachment[]) {
console.log({ value, attachments })
}
</script>
<template>
<Composer
v-model="message"
id="support-reply"
name="reply"
label="Reply"
help="Attach screenshots or PDFs when they help."
placeholder="Type your message..."
:error="error"
:invalid="!!error"
required
:precognitive="false"
:disabled="false"
:loading="sending"
:auto-resize="true"
:min-rows="2"
:max-rows="8"
:submit-on-enter="true"
:submit-on-cmd-enter="true"
allow-attachments
reorderable
:accepted-file-types="['image/png', 'image/jpeg', 'application/pdf']"
:max-file-size="10240"
store-with-form
show-character-count
:max-length="2000"
submit-label="Send"
:quick-actions="quickActions"
badge="Support"
badge-class="bg-zinc-100 text-zinc-700"
label-trailing="Required"
label-trailing-class="text-zinc-500"
tooltip="Files are submitted with the reply."
help-position="below"
layout="stacked"
control-position="start"
label-class="font-medium"
help-class="text-zinc-500"
error-class="text-red-600"
wrapper-class="max-w-2xl"
control-class="bg-white"
class="shadow-sm"
:part-classes="fieldParts"
:label-sr-only="false"
@submit="send"
/>
</template>import { useState } from 'react'
import { Composer } from '@inertiaui/form-react/components'
import type { ComposerAttachment, ComposerAttachmentValue } from '@inertiaui/form-react'
const quickActions = [
{ label: 'Thanks', value: 'Thanks for reaching out!' },
{ label: 'On it', value: 'We are looking into this now.' },
]
const fieldParts = {
editor: 'min-h-24',
item: 'bg-zinc-50',
submitButton: 'px-4',
}
export default function ReplyComposer() {
const [message, setMessage] = useState<ComposerAttachmentValue>({
text: '',
attachments: [],
})
const [error] = useState<string | null>(null)
const [sending] = useState(false)
function send(value: string, attachments: ComposerAttachment[]) {
console.log({ value, attachments })
}
return (
<Composer
value={message}
onValueChange={setMessage}
id="support-reply"
name="reply"
label="Reply"
help="Attach screenshots or PDFs when they help."
placeholder="Type your message..."
error={error}
invalid={Boolean(error)}
required
precognitive={false}
disabled={false}
loading={sending}
autoResize
minRows={2}
maxRows={8}
submitOnEnter
submitOnCmdEnter
allowAttachments
reorderable
acceptedFileTypes={['image/png', 'image/jpeg', 'application/pdf']}
maxFileSize={10240}
storeWithForm
showCharacterCount
maxLength={2000}
submitLabel="Send"
quickActions={quickActions}
badge="Support"
badgeClass="bg-zinc-100 text-zinc-700"
labelTrailing="Required"
labelTrailingClass="text-zinc-500"
tooltip="Files are submitted with the reply."
helpPosition="below"
layout="stacked"
controlPosition="start"
labelClass="font-medium"
helpClass="text-zinc-500"
errorClass="text-red-600"
wrapperClass="max-w-2xl"
controlClass="bg-white"
class="shadow-sm"
partClasses={fieldParts}
labelSrOnly={false}
onSubmit={send}
/>
)
}Attachment upload transports use the same runtime props described in Serialized Upload Configuration.
Composer is a composite editor, so it doesn't forward arbitrary native attributes or listeners to the internal textarea. See Native Attributes And Events.