Forms
Composer
A message box: a textarea that grows as the user types, inside a bordered box that also holds action buttons and optional content above and below it. Use it for chat messages, comments and replies, where Enter can send the form; for a plain multi-line field use tk:textarea.
Nothing to show
A box labelled "Message" with a two-row textarea inside. As the user types more lines the textarea grows, up to 10 rows, and then scrolls. The form sends the text under message.
Sending with Enter #
The send button sits at the bottom right of the box. With submit, Enter submits the form, which runs send(), while Shift+Enter starts a new line; Enter does nothing while the box holds only spaces. Setting $message to '' on the server empties the textarea. With submit="ctrl+enter" Enter adds a line and Ctrl+Enter (Cmd+Enter on a Mac) submits instead.
Nothing to show
Inline #
A single row: the leading actions on the left, a one-row textarea in the middle and the trailing actions on the right. The textarea still grows as lines are added: a single line is centered between the actions, and with more lines the actions stay at the bottom, next to the last one.
Nothing to show
Header and footer #
Inside the box, from top to bottom: the badge, the textarea, the footer text, and a row with the attach button on the left and the submit button on the right. The header and the footer are not shown with inline.
Nothing to show
Your own control #
The input slot replaces the textarea with another TALLKit control, here a one-line input, kept in sync with the composer's value. It must be a TALLKit control such as tk:input: a plain <input> is not bound. Give it the composer's id so the label points to it.
Nothing to show
Submitting with Ctrl+Enter #
With submit="ctrl+enter", Enter adds a line and Ctrl+Enter (Cmd+Enter on a Mac) submits the form.
Nothing to show
Rows, sizes and states #
rows sets the starting height and max-rows the most it grows; size sets the font, padding and rounding. disabled locks it.
Nothing to show
Typing indicator #
The native events of the textarea bubble to the tag; here a debounced input tells Livewire the user started typing.
Nothing to show
Customization #
Classes go to the box; textarea:textarea:class reaches the textarea itself and actions-trailing: the element around the trailing actions.
Nothing to show
Reference
tk:composer
| Prop | Type | Default | Description |
|---|---|---|---|
submit |
bool | string | array | false |
Submits the enclosing form from the keyboard. true or enter: Enter submits and Shift+Enter adds a line. ctrl+enter: Ctrl+Enter or Cmd+Enter submits. An array (['enter', 'ctrl+enter']) accepts both. |
rows |
int | 2, 1 with inline |
The rows the textarea starts with. |
maxRows |
int | 10 |
The textarea grows up to this many rows as the user types, then scrolls. |
inline |
bool | false |
Puts the actions and the textarea on one row. The header and the footer are not shown. |
header |
slot | null |
Content above the textarea, inside the box. |
footer |
slot | null |
Content below the textarea, inside the box. |
actionsLeading |
slot | null |
Content at the bottom left of the box, or on the left with inline. |
actionsTrailing |
slot | null |
Content at the bottom right of the box, or on the right with inline. |
Also accepts the field props (label, help, placeholder, size...) and the field control props (icon, loading...), and disabled and readonly. size sets the font size, padding and rounding of the box.
wire:model and x-model bind the text as a string.
Slots
| Slot | Description |
|---|---|
| default | The initial text, in place of value. Ignored inside Livewire. |
header, footer, actions-leading, actions-trailing |
As the props of the same name. |
input |
Replaces the textarea with another TALLKit control. |
Prefixes
| Prefix | Goes to |
|---|---|
textarea: |
The tk:textarea inside, with its own props and prefixes. Its class goes to a wrapper around the textarea: use textarea:textarea:class for the textarea itself. |
header: |
The element around the header. |
footer: |
The element around the footer. |
actions-leading: |
The element around the leading actions. |
actions-trailing: |
The element around the trailing actions. |
hidden: |
The hidden input that holds the value sent with the form. |
Events
The composer dispatches no events of its own. The native events of the textarea bubble to the tag: keydown, and input and change, which reach it on every change of the text.
Nothing to show
Customization
Classes and attributes on the tag go to the box (role="group"); class is also added to the element that wraps the textarea. To reach another element, prefix the attribute (listed in the Reference above).
The field props and field control props prefixes (label:, help:, control:...) also work.
Nothing to show
Accessibility
The box has role="group" and is labelled by the field label, which also points to the textarea through for, so clicking the label focuses it. The textarea carries aria-describedby for the description, the help text and the error, and aria-invalid when the field is invalid. The action buttons are ordinary buttons in the tab order after the textarea: give icon-only ones an aria-label.
| Key | Action |
|---|---|
| Enter | With submit, submits the form; otherwise adds a line. |
| Shift+Enter | Adds a line. |
| Ctrl+Enter, Cmd+Enter | With submit="ctrl+enter", submits the form. |
A key pressed while an input method is composing text (Japanese, Chinese...) never submits. A readonly composer never submits.
Behavior notes
- Submitting goes through the form's
requestSubmit(), sowire:submit,onsubmitand the browser's validation run as for a click on a submit button. Outside a form the submit key does nothing, and does not add a line either. - The box is rendered once (
wire:ignore): a Livewire update does not change the header, the footer or the actions already on the page. The text still followswire:modelboth ways. - Inside Livewire,
valueand the default slot are ignored: give the initial text throughwire:model. - Outside Livewire, the text is sent with the form by a hidden input named after
name; the textarea itself has no name. A form reset brings back the text the composer started with.