Skip to content
Focsd homeFocsd homeFocsd
Forms

Composer

The message field: a growing textarea with attach, send and stop, and a drop zone for files.

  • Tag: focsd-composer
  • Pattern: Textbox (multi-line) + file drop
  • Category: AI

Example

HTML
<focsd-composer
id="composer-demo"
placeholder="Ask anything"
accept="image/*,.pdf,.txt"></focsd-composer>
<script type="module">
const composer = document.getElementById('composer-demo');
composer.addEventListener('focsd-submit', (event) => console.log(event.detail.text, event.detail.files));
</script>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/ai';
</script>
<focsd-composer placeholder="Ask anything" accept="image/*,.pdf,.txt"></focsd-composer>

API

Attributes

AttributePropertyTypeDefault
valuevaluestring—
placeholderplaceholderstring—
labellabelstring—
busybusybooleanfalse
disableddisabledbooleanfalse
acceptacceptstring—
max-filesmaxFilesnumber10
max-file-sizemaxFileSizenumber0

Methods

MethodDescription
focus(options)Focus the textarea (not the first button, as delegated focus would).
addFiles(list)Check and attach files. Rejected files are not added; their names and reasons are announced and shown. Does nothing while disabled.

Events

EventDescription
inputThe text changed while the person types (the textarea's native event).

CSS parts

Style the inside of the component with ::part(), for example focsd-composer::part(field).

PartDescription
fieldThe whole composer; it accepts dropped files (`dragging` while files are dragged over it).
draggingAdded to the field while files are dragged over it.
drop-textThe "Drop files to attach" text shown while dragging.
attachmentsThe list of attached files.
errorWhy the last files were not attached.
textareaThe textarea.
attachThe attach button.
sendThe send button.
stopThe same button while `busy`.
iconThe icons in the buttons.

Accessibility

  • A native <textarea> named by label (default "Message"). It grows to eight lines. Enter sends; Shift+Enter adds a line. Nothing is sent while an input method (IME) composes, so choosing a candidate with Enter never sends.
  • While busy, the send button becomes Stop in the same place and keeps focus, so Tab from the field reaches it. It fires focsd-stop. Enter does nothing while busy.
  • Send, stop, attach and remove are at least 44 by 44 px. Send is aria-disabled rather than disabled when there is nothing to send, so it keeps focus.
  • Files can be attached with the button, pasted or dropped on the composer (an outline and "Drop files to attach" show while dragging). A rejected file (type, size or count) is announced assertively with the reason and also shown as text next to the field.
  • focsd-submit is cancelable: cancel it to keep the text and files. It sends the text as typed, with files as File objects.

Keyboard

KeyAction
EnterSend (not while composing text with an input method)
Shift + EnterNew line
TabMove to send or stop