Raft Design System

Components · Messages

Composer

The message box at the bottom of a conversation, with the input, its tools, attachments, @ suggestions and the pink send button inside one ink border.

Stable
import { Composer } from "@botiverse/raft-ui";

The composer is where people write a message: at the bottom of a channel, a direct message, a thread or a task's discussion. One ink border holds the input, the tools, any attachments and the pink send button. Typing @ opens a list of people and agents above it.

chat-composer/compositions/composer-default

When to use

SituationUse
Sending a message in a conversationComposer
Several lines of text saved with a formTextarea
One line of textInput

Where the composer sits in a conversation is in Conversation.

Anatomy

  • ComposerRoot: the <form> that submits the message. Required.
  • Composer: the box with the ink border. Required.
  • ComposerAttachments with one ComposerAttachment per file: 64px thumbnails in a row above the box, inside ComposerRoot and outside Composer, as Raft's message composer places them. Optional. SortableComposerAttachments (wrapping) and SortableComposerAttachmentsScroll (one scrolling row), with a SortableComposerAttachment around each, let people reorder them. The row is ComposerAttachmentsScrollArea: a horizontal ScrollArea whose thin scrollbar shows only while it scrolls, with an arrow on each side that has more attachments past it.
  • ComposerInput: the input, a <textarea> that grows with its content. Required. It is a ScrollAreaTextarea (ScrollArea): past its maximum height it scrolls with the same thin overlay scrollbar as the attachments row and the message list, shown while the pointer is over it or it scrolls. ref, className and the native props go to the textarea; wrapperClassName to the frame that holds it and the scrollbar. It takes no render: the textarea is the element the scrollbar measures and scrolls, so it can't be swapped for another.
  • ComposerToolbar: the row under the input, with:
    • ComposerActions: the tools at the start, each a ComposerIconButton (attach a file, add an image);
    • ComposerMeta: at the end, an option attached to sending (ComposerToolbarLabel with a Checkbox) and ComposerSubmit, the send button.
  • ComposerSuggestionList and its parts, driven by useComposerSuggestions: the @ suggestions above the box.
  • ComposerDropOverlay: what the box shows while files are dragged over it. Inside it, ComposerDropOverlayPrompt draws the files-and-upload icons above its children, the text your product writes in its own language ("Drop files to attach"); ComposerDropOverlayLabel is the same line without the icons.

States

chat-composer/compositions/composer-attachment-states
  • Uploading: a thumbnail shows cyan progress on its own track, inset from its edges (Shape); × in its corner cancels the upload while it runs and removes the file after. The thumbnail lies under a layer-veil cover (ComposerAttachmentUploadingOverlay) with a default-color spinner.
  • Failed: the same layer-veil cover with a danger-strong border and a line that says it failed (ComposerAttachmentFailedOverlay). Both covers use the one veil (Surfaces). File cards are in MessageAttachment.
  • Nothing to send: disable ComposerSubmit until there is text or an attachment.
  • Focus: the whole composer takes the focus ring (States).

Behavior

composer-suggestions/composer-suggestions
  • Typing @ opens the suggestion list above the composer, as wide as the composer and 8px above it, or below it when there isn't room above. It renders in a portal, like other popups, and follows the composer as the page scrolls, so a scrolling region the composer sits in, such as a comments sidebar, doesn't cut it off; It hides while the composer is scrolled out of that region. anchor changes what it is placed against (by default the nearest positioned box around it, ComposerRoot). Mount it only while it is open: focus stays in the input. Where it is rendered it leaves a hidden span, which counts for its siblings' :last-child and space-y-*. Group it with members of this conversation first, then the others. Each row shows the avatar, the name and the status in foreground-hint.
  • Let people drag files into the composer, but not folders.
  • Reordering attachments is a drag like any other (Drag and drop): a lifted copy of the thumbnail follows the hand on both axes, the thumbnail it came from stays at 40% until it moves, its slot becomes the dashed place, and a drop or a cancel glides in 160ms. Space on a focused attachment picks it up, the arrow keys move it and Space drops it. Each step is announced by the attachment's label and its position, never its id; pass your translations as messages. The lifted copy renders in document.body (container to change it), so a drawer's or a dialog's transform doesn't offset it.
  • Grow the input with its content up to a maximum height (128px), then scroll inside it. A scroll that reaches the end of the draft stops there: it doesn't carry on to the page.
  • On a phone, keep the composer on top of the keyboard when the keyboard opens. Return inserts a new line on a phone held upright (Responsive layout), so sending uses the send button.
  • Its buttons, the send button included, are controls embedded in its frame: they wear radius-chip and sit 6px from the composer's outer edge at the bottom and at each side, and 6px apart. With a mouse its icon buttons (the icon send button included) are 28px bar buttons whose glyphs keep the place of the 32px buttons, so they sit 8px from each side; the bottom stays 6px (Shape).
  • Put the composer's border on the content margin (Page structure), with 16px plus the safe area below it.
chat-composer/compositions/composer-drop-overlay

Content

  • Make the placeholder say where the message goes: Message #launch-week. Use the same words as the input's aria-label.

Accessibility

Composer has no Base UI primitive: it renders a native <form> and <textarea>. useComposerSuggestions adds the combobox pattern to the input: aria-controls points at the listbox, aria-activedescendant at the highlighted option. Arrow Up and Arrow Down move the highlight, Enter or Tab picks it, and Esc closes the list.

  • Give ComposerInput an aria-label that names the destination (Message #launch-week).
  • Give every ComposerIconButton and an icon-only ComposerSubmit an aria-label (Attach file, Send).
  • Give the suggestion list an aria-label or aria-labelledby.

Rules

  • Count the send button as the screen's pink button (Button). It is a pink icon button (size="icon-md") with aria-label="Send", on a phone and on desktop.
  • Draw one ink border around the whole group: 1.5px line-field, like a field (Shape). The tools inside it have none: ComposerIconButton is frameless.
  • Keep the input text text-body at regular weight wherever the composer sits (a channel, a thread, a comment on an attachment, a forward). Don't let it inherit the surrounding type. Make tool icons foreground-muted.
  • Under a scrolling region, such as a comment on an attachment or a note added to a forward, use a compact composer: a line-seam above it, 12px of space around it, and no fill of its own.

API

Composer, ComposerActions, ComposerAttachment, ComposerAttachmentBody, ComposerAttachmentFailedOverlay, ComposerAttachmentFile, ComposerAttachmentImage, ComposerAttachmentMeta, ComposerAttachmentRemove, ComposerAttachments

PropTypeDefault
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

ComposerAttachmentsScrollArea

One scrolling row of attachments: a horizontal ScrollArea (its thin scrollbar shows only while the row scrolls), with an arrow on each side that has more attachments past it. The ScrollArea reports the edges, so the arrows follow scrolling, resizing and attachments coming and going.

Takes the attributes of its element.

ComposerAttachmentTitle, ComposerAttachmentUploadingOverlay

PropTypeDefault
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

ComposerAttachmentUploadProgressBar

PropTypeDefault
value (required)number
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

ComposerDropOverlay, ComposerDropOverlayLabel

PropTypeDefault
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

ComposerDropOverlayPrompt

The label with the files-and-upload icon cluster above the caller's text.
PropTypeDefault
children (required)What the prompt says, such as "Drop files to attach": the caller's copy, in its locale.string | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined>
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

ComposerIconButton

PropTypeDefault
loadingBusy: shows the spinner and blocks activation (click, Enter, Space and form submission) while keeping the button focusable. A busy button is `aria-disabled`, not natively `disabled`, so the focus a press left on it stays there and is still there when the wait ends.boolean
loadingLabelThe spinner's accessible name while `loading`: say what is happening.string
focusableWhenDisabledWhether the button should be focusable when disabled.booleanfalse
nativeButtonWhether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`).booleantrue
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

ComposerInput

PropTypeDefault
hideDelayHow long the scrollbar stays after scrolling stops, as on ScrollArea.number
overscrollWhether a scroll that reaches the end carries on to the page, as on ScrollArea.ScrollAreaOverscroll
sizeThumb thickness, as on ScrollArea.ScrollAreaSize
triggerWhen the scrollbar shows, as on ScrollArea.ScrollAreaTrigger
wrapperClassNameClass of the root that holds the textarea and its scrollbar.string
wrapperStyleStyle of the root; size the textarea itself with `className` / `style`.CSSProperties

Also takes the attributes of its element.

ComposerMeta, ComposerRoot

PropTypeDefault
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

ComposerSubmit

PropTypeDefault
loadingBusy: shows the spinner and blocks activation (click, Enter, Space and form submission) while keeping the button focusable. A busy button is `aria-disabled`, not natively `disabled`, so the focus a press left on it stays there and is still there when the wait ends.boolean
loadingLabelThe spinner's accessible name while `loading`: say what is happening.string
size`md` (32px) and `icon-md` for rows, cards, banners, toolbars and panel headers; `lg` and `icon-lg` (the control height) for dialog footers, forms and beside a field; `xl` for a full-width call to action; `icon-sm` (28px, a 44px hit area) for an icon-only action on a line of a row or a card, such as a comment header's More, never in a toolbar. The size follows the place: see Button › Size by place."md" | "lg" | "xl" | "icon-sm" | "icon-md" | "icon-lg" | DeprecatedButtonSize
focusableWhenDisabledWhether the button should be focusable when disabled.booleanfalse
nativeButtonWhether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`).booleantrue
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

ComposerSuggestionAside, ComposerSuggestionContent

PropTypeDefault
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

ComposerSuggestionGroup

PropTypeDefault
separatedbooleanfalse
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

ComposerSuggestionGroupLabel

PropTypeDefault
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

ComposerSuggestionIcon

PropTypeDefault
variant"inline" | "avatar" | "framed" | "auxiliary""avatar"
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

ComposerSuggestionList

The suggestions' popup. It renders in a portal, like other popups, so a scrolling region around the composer doesn't cut it off; it is as wide as its anchor and 8px above it, and goes below it when there isn't room above. Mount it while it is open: it has no open state of its own, and focus stays in the composer. It hides while the composer is scrolled out of its region. Where it is rendered it leaves a `hidden` span, which counts for its siblings' `:last-child` and `space-y-*`. The list is a ScrollArea: `ref`, `className`, `render` and the native props (the listbox's role and id) are the scrolling element's.
PropTypeDefault
actionsRefMethods to scroll from code that the container doesn't have natively.((instance: ScrollAreaActions | null) => void | (() => void | { [UNDEFINED_VOID_ONLY]: never; }) | DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | RefObject<ScrollAreaActions | null>
anchorWhat the list is placed against: as wide as it, 8px above it, or below it when there isn't room above.Element | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null)The nearest positioned ancestor of where the list is rendered (`ComposerRoot`, or the box around the composer).
childrenThe scrolling content, in ScrollArea's own container.ReactNode
containerWhere the list is rendered: the body, or the overlay it is opened in, as other popups.HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null>
contentClassNameClass of a content element around `children`, inside the container: put padding and the content's own layout (grid, flex, `gap`, `stack-y-*`) here, so the scrollbars stay at the edges and the gutters layer is never one of the laid-out children. Only with it, `contentStyle` or `fade` is there one.string
contentRefAn element whose size is the content's, watched for size changes (such as a hidden mirror of a textarea's text). Without it each element child of the container is watched, and children added or removed.RefObject<HTMLElement | null>
contentStyleStyle of the content element; renders it, as `contentClassName` does.CSSProperties
fadeFade the content out toward an edge that has more past it. The scrollbars don't fade.boolean
hideDelayHow long the scrollbars stay after scrolling stops, in ms. At least 100 with `trigger="scroll"`.number
onEdgeChangeCalled when the area reaches or leaves an edge, and after mounting when the content overflows.(edges: ScrollAreaEdges) => void
onScrollThe container's scroll events.UIEventHandler<HTMLDivElement>
orientationThe directions the area scrolls in. Content too wide for a vertical area is cut off.ScrollAreaOrientation
overscrollWhat a scroll that reaches the end does: stop there with no bounce (`none`, the default), stop there but let Mac trackpads and iOS bounce the area (`contain`), or carry on to the page behind (`auto`, which leaves the container's own `overscroll-behavior` alone). Only in the directions the area overflows right now.ScrollAreaOverscroll
railInsetRoom in px the scrollbars keep clear at each end, such as a sticky header's height, so they don't run over it. Also settable in CSS, on the root: `--r-scroll-area-rail-inset-{top,bottom,left,right}`, which don't inherit.ScrollAreaRailInset
renderAnother element in place of ScrollArea's own `<div>`, as the container (an element or a function that gets the props). It must hold children: the gutters are its first child.ReactElement | ((props, state) => ReactElement)
sizeThumb thickness: `small` is 5px, `medium` 7px; both grow while pointed at or dragged.ScrollAreaSize
tabIndexThe container's: by default `0` while there is something to scroll.number
triggerWhen the scrollbars show. They always show while scrolling or dragging.ScrollAreaTrigger

Also takes the attributes of its element.

ComposerSuggestionMeta

PropTypeDefault
variant"code" | "text""text"
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

ComposerSuggestionOption, ComposerSuggestionTitle, ComposerToolbar, ComposerToolbarLabel

PropTypeDefault
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

SortableComposerAttachment

The lifted attachment's own slot stays in the flex flow: at 40% while it is still home, the dashed place once it stands anywhere else. DragLift holds the copy that follows the hand; the root reads these `children` for it. Live draft reorder moves this slot to the drop index; wrap skips strategy transforms so siblings FLIP via layout instead of wrong gaps.
PropTypeDefault
children (required)ReactNode
id (required)string
label (required)string

SortableComposerAttachments, SortableComposerAttachmentsScroll

Wrap / flex-pack attachment reorder (mixed widths).
PropTypeDefault
children (required)ReactNode
containerWhere the lifted copy renders: `document.body` by default, so a transformed ancestor (a drawer, a dialog) doesn't offset it. `null` renders it in place.Element | DocumentFragment
items (required)readonly string[]
messagesYour translations of the drag's instructions and announcements. Each step is said by the attachment's `label` and its position; never by its id.Partial<DragMessages>
onReorder (required)(items: string[]) => void

Changes

  • 0.104.0 · Design SystemTooltips on a touch screen, and who owns a long press ([Tooltip › Touch screens](https://raft-design.botiverse.build/components/tooltip/#touch-screens), [States › Dragging on a touch screen](https://raft-design.botiverse.build/foundations/states/#dragging-on-a-touch-screen)): on a touch screen a tooltip opens on a press and hold, on a disabled button too (focusableWhenDisabled); a long press belongs to the layer that owns it (a long-press menu, a touch drag, a link), and the tooltip takes it only when nothing else wants it. Changed in this release: TooltipTrigger, and the long-press owners ContextMenuTrigger, SortableTabsTab, SortableComposerAttachment and TaskDraggable.
  • 0.103.4 · FixedFrame insets (Popover, DropdownMenu, ContextMenu, Select, Combobox, ComboboxSelect, Tooltip, PreviewCard, CoachMark, NotificationCenter, MobileNavServerPopover, ToastPositioner, ComposerSuggestionList): --raft-frame-inset-start and --raft-frame-inset-end are the corners of the window's top band (--raft-frame-inset-top), not columns down its sides. A popup anchored under the band keeps its own padding from the window's edge; only one anchored in the band (a title-bar control, or a context menu opened in the bar) keeps 8px clear of a corner.
  • 0.103.3 · FixedFrame insets (useFrameInsets, frameCollisionBoundary): opening a positioned popup (Popover, DropdownMenu, Select, Combobox, ComboboxSelect, ContextMenu, Tooltip, PreviewCard, NotificationCenter, MobileNavServerPopover, ComposerSuggestionList) no longer stalls the main thread when --raft-frame-inset-* holds a calc() or env(titlebar-area-*) expression on an overlay title bar.
  • 0.82.0 · BreakingComposerDropOverlayPrompt takes its text as children, which is required: the icon cluster stays, and the text under it is what you pass. It no longer falls back to the built-in "Drop files to attach", and children no longer replace the icons.
  • 0.81.0 · FixedDragLift renders the copy in document.body by default: the lifted copy goes through a portal to the body unless container names another element, or null keeps it in place; the portal keeps the theme scope it was rendered in. TaskDragOverlay follows, as SortableTabsList and SortableComposerAttachments already did.
  • 0.74.0 · ChangeduseScrollAreaContainer gives its container the overflow: the classes in containerProps.className make the element scroll in the orientation, as ScrollArea's own container does (vertical: overflow-y: auto and overflow-x: hidden; horizontal: the other way round; both: auto), so the element needs no overflow class of its own and nothing for raft-ui/prefer-scroll-area to report. ComposerInput and ActivityInboxViewport no longer carry overflow-y-auto.
  • 0.73.0 · ChangedEvery region that scrolls is a ScrollArea: PanelScrollViewport, ActivityInboxViewport, SearchShellViewport, NotificationCenterScroller, FilesViewport, TasksPanelViewport, ChoiceList's scroller, MobileNavServerPopoverList, ComposerSuggestionList, AnnouncementDialogBody, MessageActionCardScopeListViewport and DialogNav show ScrollArea's overlay scrollbar instead of the platform's. Native scrolling stays only in the places scroll-area.md lists, each with its reason, and a test fails on any other.
  • 0.10.0 · Breaking ChangesField frames (Input, Textarea, InputGroup, Select, Combobox, ComboboxSelect, Composer, option Card, SearchTrigger) are drawn at 1px in line-field instead of 1.5px, on the phone too.