Skip to content

Message field

Pro

A rounded field for writing something to send (a comment, a reply, a chat message) that grows from a pill into a box, with a send button, tools that open into their own row on focus, a reply banner, attachments and suggestions while typing (people after @, tags after #, emoji after :); plus its trigger. Not an M3 component (@windmorph/react-pro).

import { MessageField, MessageFieldFrame, MessageFieldTrigger, MessageFieldSend, useMessageField, useMessageFieldInput, useCoarsePointer } from '@windmorph/react-pro';

Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.

Keyboard

Message field keyboard
KeyAction
EnterSends, with submitOn="enter" (the default) on a computer. On a touch screen, with submitOn="mod-enter" or "none", it starts a new line. Enter that confirms an input method's candidate never sends.In the text
Shift + EnterStarts a new line.In the text
Ctrl + EnterSends, with submitOn "enter" or "mod-enter" (⌘ + Enter on a Mac).In the text
EscapeDismisses the suggestion list while it (or its loading row) shows, until what follows its @, # or : changes; otherwise calls onEscape when given, for example to cancel a reply.In the text
Arrow Up or Arrow DownMoves the active suggestion up or down the list, wrapping, and scrolls it into the list’s view; it shows the focus layer and an inset focus ring.With a suggestion list open
Enter or TabPuts the active suggestion in (@Name , #tag or the emoji) in place of what was typed, instead of sending or leaving the field. With Shift, Ctrl or ⌘ they stay the field’s: Shift + Enter still starts a new line and Ctrl + Enter still sends.With a suggestion list open
Arrow Left or Arrow RightMoves between the tools, wrapping at the ends.In the tools
Home or EndMoves to the first or last tool.In the tools
Enter or SpaceSends. Focus and the caret stay in the text.On Send
Enter or SpacePresses MessageFieldTrigger, or follows it with href (Enter only).On MessageFieldTrigger
  • Nothing is sent while the text is blank (unless sendable), over maxLength, or already sending.
  • A suggestion list opens only as the text changes (with mentions, tags or emojiSuggestions), never as the caret moves, and @, # and : open one only at the start of the text or after a space (@ and : also after opening punctuation), so times and addresses never do.
  • The tools are mirrored in right-to-left text, and so are the slots and the counter. Arrow keys in the toolbars follow the laid-out direction, including a dir="rtl" region of a left-to-right app.

Screen reader

Role
The text is a textarea. The tools are a toolbar of buttons; Send, the banner close and the slot buttons are icon buttons. MessageFieldTrigger is a button, or a link with href. A suggestion list is a listbox of options, in a popover outside the field.
Accessible name
The text is named by the visible label, aria-label or aria-labelledby; the types require one, so the placeholder is never the only name. The tools toolbar is named labels.tools ("Tools"), Send labels.send ("Send", also its tooltip) and the banner close labels.closeBanner ("Close"). MessageFieldTrigger is named by its prompt, or its aria-label. The suggestion lists are named labels.mentionSuggestions ("People to mention"), labels.tagSuggestions ("Tags") and labels.emojiSuggestions ("Emoji suggestions"); each option by its label, and an emoji by its name and the shortcode shown.
States announced
The text has aria-invalid (also while over maxLength) and aria-required, and aria-describedby links supportingText and errorMessage. Send is disabled while there is nothing to send. While sending it stays focusable with aria-disabled, its name gains labels.sending ("Send, Sending"), and the field announces labels.sending politely when a send starts (the core IconButton's pending state; its loading indicator is hidden from assistive tech and shows after 200ms). With mentions, tags or emojiSuggestions the text has aria-autocomplete="list"; while a list shows it points at it (aria-controls) and at the active suggestion (aria-activedescendant), which is aria-selected.
  • The error is an alert region that goes into the page before its message, so screen readers announce the message when it arrives. While it shows, the supporting text is visually hidden but still read.
  • A polite live region announces the limit once per change: labels.nearLimit from counterThreshold, then labels.atLimit and labels.overLimit. The visible counter is hidden from assistive tech.
  • MessageFieldTrigger's avatar, tools and trailing icon are decorative (aria-hidden).
  • A second polite live region announces labels.sending when a send starts while focus is in the text.
  • A polite status says how many suggestions the list shows (labels.mentionResults, labels.tagResults, labels.emojiResults: "3 people", "2 tags", "5 emoji"). It goes into the page before its first count, so the first count is announced too. A slow search, or the emoji data loading, shows a loading indicator named labels.mentionLoading, labels.tagLoading or labels.emojiLoading.
  • Avatars, tag icons and emoji in a suggestion list are decorative (aria-hidden): the option's name carries them.

Focus

  • The text, the tools (one Tab stop), the slot buttons and Send are in Tab order. With toolbarPlacement below the text, the toolbar row follows the text in Tab order. Pressing the field anywhere outside its controls puts the caret in the text, and so do Send and the banner close.
  • Keyboard focus in the text draws M3's focus indicator around the whole field: a 3px secondary outline 2px outside; pointer focus draws only the thicker focus border.
  • Focus stays in the text while a suggestion list is open: the list is pointed at, not focused, and pressing a suggestion picks it without taking focus. The suggestion reached with the arrow keys shows the focus layer and an inset focus ring; in forced-colours mode it is outlined in Highlight.
  • Putting the caret back in the text (after a press on the field, Send, the banner close or insertText) never scrolls the page. The app's own focus() brings a field that is wholly off screen into view with a nearest, smooth scroll (instant under reduced motion).

Touch target

  • The field is 40, 48 or 56px tall (sm, md, lg). Its buttons are extra-small or small icon buttons with 48 × 48px touch targets, spaced 48px apart so the targets never overlap.
  • Its icon buttons stay at density 0 in a dense theme, so their targets keep their size and spacing while the field keeps its height.
  • MessageFieldTrigger is as tall as the field; at sm (40px) it gets an invisible 48 × 48px touch target. It grows with larger text instead of cutting it.

Motion

  • Under reduced motion nothing moves or scales: rows open, Send appears and the field grows without movement, and an invalid send does not shake the field. The fades stay on their effects timing, so the rows, Send, its icon and the loading indicator still fade in and out.
  • The press ripple appears at full size without growing, and corner changes snap.
  • A suggestion list opens and closes as the core menu does, so under reduced motion it loses its movement.

What you need to do

  • Name the field (label, aria-label or aria-labelledby) for what is being written ("Write a comment"), not only with a placeholder.
  • Give every tool an aria-label, and translate every built-in word through labels, including the limit announcements and the suggestion lists' names, loading words and counts.
  • With mentions or tags, give each suggestion a label that names it: it is the option's name and the text put in.
  • Explain a failed send in errorMessage with invalid, and keep pending on while a send is in flight.
  • The field announces nothing when it refuses a pasted or dropped file off accept: handle onFilePick (or onFileReject) and say why in words a screen reader hears too, such as a snackbar, once for the whole paste or drop.
  • In forced-colours mode the field's border is CanvasText, Highlight while focused and GrayText while disabled; keep classNames overrides from removing it.