Skip to content

Rich message field

Pro

A message field that formats as you type, with markers in plain text: bold, italic, strike, code, links, lists, quotes and code blocks, with a formatting toolbar, and suggestions while typing (@mentions of people, #tags and emoji after :); plus FormattedText, which shows what it wrote. Not an M3 component (@windmorph/react-pro/rich-text, with Tiptap).

import { RichMessageField, FormattingToolbar, FormattedText, useRichMessageField } from '@windmorph/react-pro/rich-text';

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

Rich message field keyboard
KeyAction
EnterSends, with submitOn="enter" (the default) on a computer. In a list it starts the next item (an empty one ends the list), in a code block a new line, and on a touch screen a new paragraph.In the text
Shift + EnterStarts a new paragraph, or a new line in a list or code block.In the text
Ctrl + EnterSends, unless submitOn="none".In the text
Ctrl + B or Ctrl + IToggles bold or italic at the caret or on the selection.In the text
Ctrl + Shift + X or Ctrl + Shift + CToggles strikethrough or inline code.In the text
EscapeDismisses the suggestion list while it (or its loading row) shows (typing on in the same @, # or : shows it again); otherwise calls onEscape when given.In the text
EscapeCloses the link dialog; focus returns to the text.In the link dialog
Arrow Up or Arrow DownMoves the active suggestion up or down the list, wrapping, and shows it with the focus layer and an inset focus ring.With a suggestion list open
Enter or TabPuts the active suggestion in: a person as a mention token, a tag as a tag token, an emoji as text. 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 buttons, wrapping at the ends.In the tools and the formatting toolbar
Home or EndMoves to the first or last button, without scrolling the page.In the tools and the formatting toolbar
Enter or SpaceToggles a format, or shows and hides the formatting toolbar (the Aa tool), keeping the caret in the text. Link opens a dialog asking for the address; on a link it removes it.On a formatting button
  • On a Mac, ⌘ takes the place of Ctrl.
  • Typing the marker format (*bold*, - , ```) formats as you go, so every format is reachable without the toolbar. Enter that confirms an input method's candidate never sends.
  • Arrow keys in the toolbars follow the laid-out direction, so they are mirrored in right-to-left text, including a dir="rtl" region of a left-to-right app.

Screen reader

Role
The editor is a textbox with aria-multiline. The tools and the formatting buttons are two toolbars of icon buttons; the formatting buttons and the Aa tool are toggle buttons. A separator divides the formatting groups. A suggestion list (people, tags or emoji) is a listbox of options. Link asks in a dialog (pressing outside it cancels).
Accessible name
The editor is named by label, aria-label or aria-labelledby (required), and described by the supporting text, error and counter as MessageField is. The formatting toolbar and the Aa tool are named labels.formatting ("Formatting"), each format by its label ("Bold", "Bulleted list"), and the suggestion lists labels.mentionSuggestions ("People to mention"), labels.tagSuggestions ("Tags") and labels.emojiSuggestions ("Emoji suggestions"); an emoji option by its name and the shortcode shown.
States announced
The formatting buttons are pressed where their format is on (aria-pressed). The editor has aria-invalid, aria-required, aria-disabled and aria-readonly as they apply. With mentions, tags or emojiSuggestions it 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 field sets these three itself, so its props leave them out.
  • A polite status says how many suggestions the list shows (labels.mentionResults, labels.tagResults, labels.emojiResults). 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 ("Finding people"), labels.tagLoading ("Finding tags") or labels.emojiLoading ("Loading emoji").
  • In FormattedText, a mention reads @Name and a tag #tag, or as renderMention and renderTag draw them. In a suggestion list, each label and second line is isolated (<bdi>), so #design keeps its order in right-to-left text.
  • In FormattedText, a code block takes keyboard focus (with M3's focus indicator) so a long line can be scrolled, unless it sits inside something pressable.
  • Avatars, tag icons and emoji in a suggestion list are decorative (aria-hidden), and the limit announcements, error and Send are the MessageField's.

Focus

  • 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 formatting buttons and the Aa tool don't take focus on a press either, so the selection stays.
  • The tools and the formatting toolbar are one Tab stop each. The link dialog focuses its address field, and closing it puts focus back in the text. When the formatting toolbar sits below the text (compact windows, or formattingPlacement="bottom"), it follows the text in Tab order too.
  • Keyboard focus in the text draws M3's focus indicator around the whole field. In a suggestion list, the suggestion reached with the arrow keys shows the focus layer and an inset focus ring; the first suggestion and the one under the pointer show the hover layer. In forced-colours mode the active suggestion is outlined in Highlight.
  • Putting the caret back in the text (a press on the field or a tool, a format, the link dialog closing, insertText) never lets the editor scroll the page. The app's own focus() brings a field that is wholly off screen into view with a nearest, smooth scroll.

Touch target

  • The formatting buttons, the Aa tool and the other field buttons are icon buttons with 48 × 48px touch targets. They stay at density 0 in a dense theme, and on its own (formatting="none" with a FormattingToolbar elsewhere) the toolbar spaces its 40px buttons 8px apart, so the targets never overlap.
  • Each suggestion is a full-width row, 44px tall at density 0.

Motion

  • Growing and shrinking by a line slide on the field's spring, as in MessageField; getting shorter eases without overshoot. Under reduced motion the height changes at once.
  • Under reduced motion autoFocus and the app's focus() bring the field into view at once instead of gliding. Nothing moves or scales, but the fades stay on their effects timing: the field's rows, Send, its icon, the loading indicator and the link dialog still fade, as in MessageField.
  • A suggestion list opens and closes as the core menu does, so under reduced motion it loses its movement, and its pressed ripple appears at full size without growing.

What you need to do

  • Name the field for what is being written ("Write a comment"), not only with a placeholder.
  • Translate every word through labels, including each format, the link dialog and the suggestion lists' names, loading words and counts.
  • With mentions or tags, give each person or tag a label that names it; it is the option's text and the inserted token.
  • 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 inline code, code blocks and quotes keep a CanvasText border, and the suggestion list keeps a border.