Skip to content
Slotted

Inline Message

One sentence about one field or one control, with a tone, a mark, and a severity word a screen reader reads before it.

Error:Enter the tax ID printed on the invoice.

Installation

The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes
tsx
import { InlineMessage, InlineMessageActions,  InlineMessageDefaultsProvider } from '@slotted/react';

When to use it

InlineMessage is one sentence about one field or one control: a hint, an error, a warning, a confirmation or a wait. A message about a section or a page is an Alert, which frames it with a title, a description and a control that puts it away. Inside a Field, FieldDescription and FieldError already render an inline message with the identifier and the states the field provides, so a form field needs no InlineMessage of its own. Use InlineMessage for a control outside a field, such as the result of a check beside a button. A Toast is for an outcome that appears over the page and leaves on its own; an inline message stays in the flow of the page until your code removes it.

Tones

tone says what the message is about. secondary, the default, is help: no mark, no severity word and the muted ink. accent and info draw the information mark and no word. success, warning and danger are severities: each draws its own mark and writes “Success:”, “Warning:” or “Error:” in text a screen reader reads before the sentence.

Use the SKU printed on the shelf label.

Prices are shown in euros.

Carrier rates were updated on Monday.

Success:Pickup scheduled for 09:30.

Warning:Only 4 units are left at this location.

Error:This SKU is already registered.

Sizes

size sets the type step. sm, the default, sits beside a compact field and md beside a large field. Both follow the control scales, so a denser theme shrinks them with the controls around them.

Error:The reorder point must be a whole number.

Error:The reorder point must be lower than the stock ceiling.

Marks

mark chooses what is drawn before the sentence. glyph, the default, is the mark of the tone. dot is one bullet in the ink of the tone, the same shape for every tone, so a column of messages starts on one edge. none draws nothing and takes no room, so the tone is read from the ink, and the ring of loading still appears. hideIcon removes the part, ring included, for a message that carries its own artwork beside it. To replace the mark, pass icon in React or project an element with slInlineMessageIcon in Angular. The last message draws a clock in the place of the warning mark.

Warning:Carrier pickup moved to 14:00.

Warning:Pallet 118 is missing a label.

Warning:Dock 3 closes at 18:00.

Warning:Two orders share one delivery slot.

Warning:Orders placed after 16:00 ship tomorrow.

Severity word

A reader who cannot see the message hears only its text, so a severity is also a word. The word is clipped from sight and sits first in the markup. prefix replaces it, and the empty string removes it for a sentence that already names the severity. A screen reader reads the three messages as “Error: Enter a valid tax ID.”, “Overdue: Invoice 4822 was due on March 3.” and “Error: the tax ID needs 9 digits.”. An application translates the words once with InlineMessageDefaultsProvider in React or provideInlineMessageDefaults in Angular.

Error:Enter a valid tax ID.

Overdue:Invoice 4822 was due on March 3.

Error: the tax ID needs 9 digits.

States

loading turns the mark into a ring that turns inside the same box, so the message keeps its size when the wait ends. disabled mutes the ink and stops the ring, because a message about a control nobody can use is not waiting for anything. The ring also stops under reduced motion. A disabled message stays in the accessibility tree.

Checking the carrier rates…

Error:The address cannot be edited while the order ships.

Syncing stock counts…

Waiting for a result

A check that returns after a moment sets loading while it runs and tone when it answers. The message is rendered from the start with reserve and live="polite", so the page does not move and a screen reader announces each sentence set in it. Press the button: the check takes 1.8 seconds.

Announcing a message

live is off by default, because a message already on the page when it loads is announced by nothing. polite writes role="status" on the message and waits for the screen reader to finish its sentence. assertive writes role="alert" and interrupts it. Use them for a message that arrives after the page. Render the message before it has a sentence, as here with reserve: a screen reader announces a change in a live region it already knows. In Angular, write the sentence between the tags with no space around it, so an empty one leaves the message empty.

Success:

Holding the line open

reserve holds one line of the message open whether or not it has a sentence, and the mark and the word withdraw when it has none. Render the message every time and nothing below it moves when the error arrives. Both columns render the message; only the second has a sentence, and the second fields sit at the same height.

Error:

Error:Order at most 500 units at once.

Actions

Put the answers a message offers after its sentence: InlineMessageActions in React, an element with slInlineMessageActions in Angular. The message becomes a group named by its sentence, the live role moves to the sentence so a screen reader does not announce the buttons, and the buttons take the size of the message. In Angular, write the message on a div, because a paragraph cannot hold a button. Press an answer to settle the quantity.

Warning:Order 4821 lists 240 units. Did you mean 24?

Pointing a control at the message

A message does not know which control it describes. Set aria-invalid on the control and aria-errormessage to the identifier of the message; on TextField, invalid writes aria-invalid. In React, pass the message an id from useId. In Angular, exportAs hands the identifier to the template: #message="slInlineMessage" and message.messageId. A message with no id generates one, and an id you write is never replaced.

Error:The EIN has 8 digits and needs 9.

Accessibility

  • A message about a section, a page or the outcome of a command belongs in an Alert. InlineMessage is the message of one field or one control, under or beside it.
  • There is no WAI-ARIA APG pattern for a message attached to a field. Three documents cover it between them: the APG Alert Pattern (w3.org/WAI/ARIA/apg/patterns/alert/) for the announcing behavior, MDN’s aria-errormessage reference for the wiring, and WCAG 2.2 Understanding 3.3.1 Error Identification for the requirement that the error be identified in text.
  • The severity is a word, not only a color and a mark. A reader who cannot see the message hears the sentence and nothing else, so InlineMessage writes “Error:”, “Warning:” or “Success:” in clipped text before it — GOV.UK’s Error message component publishes the idea for errors, and this generalizes it to every severity and to a table an application replaces once through the provider.
  • The live role goes on the message itself. Alert puts its role on an inner part because it has a dismiss button beside its text and MDN’s alert role reference restricts the role to text content; InlineMessage without actions owns no controls, so the element that is the text is the element that announces. With actions, the live role moves to the sentence. live defaults to off, because a message already present when the page finishes loading is announced by nothing whatever role it carries.
  • Wiring is the control’s job and the identifier is InlineMessage’s. MDN: set aria-invalid="true" on the control, then aria-errormessage to the id of the element holding the message. InlineMessage generates an id with useId when the page states none, and never replaces one the page wrote.
  • The mark is aria-hidden, because it repeats what the severity word already says. Under forced colors it keeps its silhouette in CanvasText — the mark of each severity has a shape of its own, which is what tells an error from a note when every color has been replaced, which is WCAG 2.2 1.4.1.
  • A disabled message is muted to a measured color rather than faded by opacity, and its ring stops: disabled takes precedence over loading, and a control nobody can use is not waiting for anything. Nothing is removed from the accessibility tree, because a message about a disabled field is still a message.
  • InlineMessage never becomes a tooltip. The message is visible text in the flow of the page, which is the requirement WCAG 2.2 3.3.1 states and the one a hover-only error fails for every reader who does not hover.

API

InlineMessage

Props

tone'accent' | 'secondary' | 'info' | 'success' | 'warning' | 'danger'Default secondary
What the message is about, and therefore which mark it draws and which word a reader hears first. secondary is help: no mark, no word, and the neutral muted ink.
size'sm' | 'md'Default sm
The type step. sm beside a compact field, md beside a large field; both read the control scales, which the theme restates per density.
live'off' | 'polite' | 'assertive'Default off
Whether the message announces itself. polite writes role="status" and assertive writes role="alert", both on this element, or on the sentence when the message holds actions.
mark'glyph' | 'dot' | 'none'Default glyph
Which mark is drawn. glyph is the tone’s own silhouette; dot is one neutral bullet in the tone’s ink, the same shape for every tone including help; none draws nothing, and the tone is said by the ink and the weight of the sentence. Field and FieldGroup ask for none, because a silhouette under every control of a form is texture rather than a warning.
prefixstring
The word read before the message. Unstated is the tone’s own; the empty string removes it, for a sentence that already names the severity.
hideIconbooleanDefault false
Draws no mark at all. The severity word stays, because it is what a reader hears rather than what a reader sees.
iconReactNode
Replaces the tone’s mark, keeping its box, its size and its place on the first line. Angular projects an element carrying slInlineMessageIcon instead.
loadingbooleanDefault false
The message is waiting for something: the mark becomes a ring turning at the same duration Button’s does, and stopping under reduced motion.
disabledboolean
Unstated rather than false, so a Field around the message can answer it. Stated, it wins: the ink is muted and the ring stops.
reservebooleanDefault false
Holds one line box of InlineMessage’s own leading open whether or not there is a message, so a form rendering the message unconditionally never moves when the error arrives.
idstringDefault generated
What aria-describedby or aria-errormessage points at. InlineMessage generates one from useId when the page states none, so the element is always addressable.

Composition

render(props) => ReactNode
Substitutes the rendered element and hands it every data attribute. A ul is how one message carries a list of failures instead of a sentence.
refRef<HTMLParagraphElement>
Reaches the element. There is no imperative handle beyond it: InlineMessage holds no state and moves nothing, so there is nothing to call.
InlineMessageDefaultsProvider{ tone, size, mark, live, prefixes }
On a subtreeSets the axes once, and the table of severity words, merged over the shipped one so a single word can be replaced alone.
InlineMessageActionscomponent
Holds the answers the message offers, after its sentence. The buttons inside take the size of the message.
childrenReactNode
The sentence, wrapped by InlineMessage in the text part. Undefined or an empty string leaves that part empty, which is what reserve draws nothing in.

Parts

PartElementRequiredPurpose
rootp, or the element render returnsYesThe message. Carries data-ui="inline-message", the three axes, data-loading, data-disabled, data-reserve, the identifier a control points at, and the live role.
prefixspanNoThe severity in words — Error:, Warning:, Success: — clipped from sight and first in the DOM so a screen reader reads it before the message. Absent for the two tones that are not severities, and for a message with nothing to say.
iconspanNoThe tone’s mark, drawn as a mask from the foundation’s status glyph set and hidden from assistive technology. Becomes a turning ring while loading, holds the page’s own artwork when icon is passed, and is absent when hideIcon.
textspanYesThe sentence. Written by InlineMessage around children, which is what makes “is there a message?” a question the stylesheet can ask and keeps a message holding a link one grid item rather than two.
actionsdivNoThe answers the message offers (InlineMessageActions), after the sentence and wrapping under it. Present, the root is a div with role="group" named by the sentence, the live role moves to the sentence, and the buttons take the message size.

Theming

Each token is a CSS custom property: set it in a theme, or on any element to retune every inline message inside it.

Inline Message tokens

TokenDefault
--slotted-inline-message-actions-gapvar(--_column-gap)
--slotted-inline-message-actions-offsetvar(--slotted-space-2, 0.25rem)
--slotted-inline-message-column-gapvar(--slotted-space-4, 0.5rem)
--slotted-inline-message-font-familyvar(--slotted-control-font-family, sans-serif)
--slotted-inline-message-line-heightvar(--slotted-line-height-md, 1.5)

Theme tokens it reads

TokenDefault
--slotted-border-width-thin1px
--slotted-control-font-familyvar(--slotted-font-family-sans)
--slotted-control-font-size-mdcomfortable 13px · compact 12px · dense 12px
--slotted-control-font-size-smcomfortable 12px · compact 12px · dense 12px
--slotted-disabled-foregroundSet per scheme by the theme
--slotted-duration-loop-fast700ms
--slotted-line-height-md1.5
--slotted-radius-full9999px
--slotted-space-20.25rem
--slotted-space-40.5rem
--slotted-text-box-edgecap alphabetic
--slotted-text-mutedSet per scheme by the theme
--slotted-tone-accent-textSet per scheme by the theme
--slotted-tone-danger-textSet per scheme by the theme
--slotted-tone-info-textSet per scheme by the theme
--slotted-tone-success-textSet per scheme by the theme
--slotted-tone-warning-textSet per scheme by the theme