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.
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.
When to use
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.ComposerAttachmentswith oneComposerAttachmentper file: 64px thumbnails in a row above the box, insideComposerRootand outsideComposer, as Raft's message composer places them. Optional.SortableComposerAttachments(wrapping) andSortableComposerAttachmentsScroll(one scrolling row), with aSortableComposerAttachmentaround each, let people reorder them. The row isComposerAttachmentsScrollArea: 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 aScrollAreaTextarea(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,classNameand the native props go to the textarea;wrapperClassNameto the frame that holds it and the scrollbar. It takes norender: 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 aComposerIconButton(attach a file, add an image);ComposerMeta: at the end, an option attached to sending (ComposerToolbarLabelwith a Checkbox) andComposerSubmit, the send button.
ComposerSuggestionListand its parts, driven byuseComposerSuggestions: the @ suggestions above the box.ComposerDropOverlay: what the box shows while files are dragged over it. Inside it,ComposerDropOverlayPromptdraws the files-and-upload icons above its children, the text your product writes in its own language ("Drop files to attach");ComposerDropOverlayLabelis the same line without the icons.
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-veilcover (ComposerAttachmentUploadingOverlay) with a default-color spinner. - Failed: the same
layer-veilcover with adanger-strongborder and a line that says it failed (ComposerAttachmentFailedOverlay). Both covers use the one veil (Surfaces). File cards are in MessageAttachment. - Nothing to send: disable
ComposerSubmituntil there is text or an attachment. - Focus: the whole composer takes the focus ring (States).
Behavior
- 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.
anchorchanges 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 ahiddenspan, which counts for its siblings':last-childandspace-y-*. Group it with members of this conversation first, then the others. Each row shows the avatar, the name and the status inforeground-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
labeland its position, never its id; pass your translations asmessages. The lifted copy renders indocument.body(containerto 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-chipand 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.
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
ComposerInputanaria-labelthat names the destination (Message #launch-week). - Give every
ComposerIconButtonand an icon-onlyComposerSubmitanaria-label(Attach file, Send). - Give the suggestion list an
aria-labeloraria-labelledby.
Rules
- Count the send button as the screen's pink button (Button). It is a pink icon button (
size="icon-md") witharia-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:ComposerIconButtonis frameless. - Keep the input text
text-bodyat 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 iconsforeground-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-seamabove it, 12px of space around it, and no fill of its own.
API
Composer, ComposerActions, ComposerAttachment, ComposerAttachmentBody, ComposerAttachmentFailedOverlay, ComposerAttachmentFile, ComposerAttachmentImage, ComposerAttachmentMeta, ComposerAttachmentRemove, ComposerAttachments
Also takes the attributes of its element.
ComposerAttachmentsScrollArea
Takes the attributes of its element.
ComposerAttachmentTitle, ComposerAttachmentUploadingOverlay
Also takes the attributes of its element.
ComposerAttachmentUploadProgressBar
Also takes the attributes of its element.
ComposerDropOverlay, ComposerDropOverlayLabel
Also takes the attributes of its element.
ComposerDropOverlayPrompt
Also takes the attributes of its element.
ComposerIconButton
Also takes the attributes of its element.
ComposerInput
Also takes the attributes of its element.
ComposerMeta, ComposerRoot
Also takes the attributes of its element.
ComposerSubmit
Also takes the attributes of its element.
ComposerSuggestionAside, ComposerSuggestionContent
Also takes the attributes of its element.
ComposerSuggestionGroup
Also takes the attributes of its element.
ComposerSuggestionGroupLabel
Also takes the attributes of its element.
ComposerSuggestionIcon
Also takes the attributes of its element.
ComposerSuggestionList
Also takes the attributes of its element.
ComposerSuggestionMeta
Also takes the attributes of its element.
ComposerSuggestionOption, ComposerSuggestionTitle, ComposerToolbar, ComposerToolbarLabel
Also takes the attributes of its element.
SortableComposerAttachment
SortableComposerAttachments, SortableComposerAttachmentsScroll
Related
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 ownersContextMenuTrigger,SortableTabsTab,SortableComposerAttachmentandTaskDraggable. - 0.103.4 · FixedFrame insets (
Popover,DropdownMenu,ContextMenu,Select,Combobox,ComboboxSelect,Tooltip,PreviewCard,CoachMark,NotificationCenter,MobileNavServerPopover,ToastPositioner,ComposerSuggestionList):--raft-frame-inset-startand--raft-frame-inset-endare 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 acalc()orenv(titlebar-area-*)expression on an overlay title bar. - 0.82.0 · Breaking
ComposerDropOverlayPrompttakes its text aschildren, 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 · Fixed
DragLiftrenders the copy indocument.bodyby default: the lifted copy goes through a portal to the body unlesscontainernames another element, ornullkeeps it in place; the portal keeps the theme scope it was rendered in.TaskDragOverlayfollows, asSortableTabsListandSortableComposerAttachmentsalready did. - 0.74.0 · ChangeduseScrollAreaContainer gives its container the overflow: the classes in
containerProps.classNamemake the element scroll in theorientation, as ScrollArea's own container does (vertical:overflow-y: autoandoverflow-x: hidden; horizontal: the other way round; both:auto), so the element needs no overflow class of its own and nothing forraft-ui/prefer-scroll-areato report.ComposerInputandActivityInboxViewportno longer carryoverflow-y-auto. - 0.73.0 · ChangedEvery region that scrolls is a ScrollArea:
PanelScrollViewport,ActivityInboxViewport,SearchShellViewport,NotificationCenterScroller,FilesViewport,TasksPanelViewport, ChoiceList's scroller,MobileNavServerPopoverList,ComposerSuggestionList,AnnouncementDialogBody,MessageActionCardScopeListViewportandDialogNavshow 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, optionCard,SearchTrigger) are drawn at 1px inline-fieldinstead of 1.5px, on the phone too.