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.
import { InlineMessage } from '@slotted/react/inline-message';export default function InlineMessageBasic() { return <InlineMessage tone="danger">Enter the tax ID printed on the invoice.</InlineMessage>;}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.
pnpm add @slotted/react @slotted/theme @slotted/themesimport { 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.
import { InlineMessage } from '@slotted/react/inline-message';import { Stack } from '@slotted/react/stack';export default function InlineMessageTones() { return ( <Stack gap={2}> <InlineMessage tone="secondary">Use the SKU printed on the shelf label.</InlineMessage> <InlineMessage tone="accent">Prices are shown in euros.</InlineMessage> <InlineMessage tone="info">Carrier rates were updated on Monday.</InlineMessage> <InlineMessage tone="success">Pickup scheduled for 09:30.</InlineMessage> <InlineMessage tone="warning">Only 4 units are left at this location.</InlineMessage> <InlineMessage tone="danger">This SKU is already registered.</InlineMessage> </Stack> );}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.
import { InlineMessage } from '@slotted/react/inline-message';import { Stack } from '@slotted/react/stack';export default function InlineMessageSizes() { return ( <Stack gap={3}> <InlineMessage size="sm" tone="danger"> The reorder point must be a whole number. </InlineMessage> <InlineMessage size="md" tone="danger"> The reorder point must be lower than the stock ceiling. </InlineMessage> </Stack> );}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.
import { Glyph, Icon } from '@slotted/react/icon';import { InlineMessage } from '@slotted/react/inline-message';import { Stack } from '@slotted/react/stack';export default function InlineMessageMarks() { return ( <Stack gap={2}> <InlineMessage mark="glyph" tone="warning"> Carrier pickup moved to 14:00. </InlineMessage> <InlineMessage mark="dot" tone="warning"> Pallet 118 is missing a label. </InlineMessage> <InlineMessage mark="none" tone="warning"> Dock 3 closes at 18:00. </InlineMessage> <InlineMessage hideIcon tone="warning"> Two orders share one delivery slot. </InlineMessage> <InlineMessage icon={ <Icon> <Glyph name="clock" /> </Icon> } tone="warning" > Orders placed after 16:00 ship tomorrow. </InlineMessage> </Stack> );}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.
import { InlineMessage } from '@slotted/react/inline-message';import { Stack } from '@slotted/react/stack';export default function InlineMessagePrefix() { return ( <Stack gap={2}> <InlineMessage tone="danger">Enter a valid tax ID.</InlineMessage> <InlineMessage prefix="Overdue:" tone="danger"> Invoice 4822 was due on March 3. </InlineMessage> <InlineMessage prefix="" tone="danger"> Error: the tax ID needs 9 digits. </InlineMessage> </Stack> );}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…
import { InlineMessage } from '@slotted/react/inline-message';import { Stack } from '@slotted/react/stack';export default function InlineMessageStates() { return ( <Stack gap={2}> <InlineMessage loading>Checking the carrier rates…</InlineMessage> <InlineMessage disabled tone="danger"> The address cannot be edited while the order ships. </InlineMessage> <InlineMessage disabled loading> Syncing stock counts… </InlineMessage> </Stack> );}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.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Inline } from '@slotted/react/inline';import { InlineMessage } from '@slotted/react/inline-message';import { Stack } from '@slotted/react/stack';type Check = 'checking' | 'done' | 'idle';const SENTENCES: Record<Check, string> = { checking: 'Checking stock in Rotterdam…', done: '142 units in stock in Rotterdam.', idle: '',};export default function InlineMessagePending() { const [check, setCheck] = useState<Check>('idle'); function handleCheck() { setCheck('checking'); setTimeout(() => setCheck('done'), 1800); } return ( <Stack gap={3}> <Inline gap={2}> <Button disabled={check === 'checking'} onClick={handleCheck} variant="outline"> Check stock in Rotterdam </Button> </Inline> <InlineMessage live="polite" loading={check === 'checking'} reserve tone={check === 'done' ? 'success' : 'secondary'} > {SENTENCES[check]} </InlineMessage> </Stack> );}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:
Error:
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Inline } from '@slotted/react/inline';import { InlineMessage } from '@slotted/react/inline-message';import { Stack } from '@slotted/react/stack';type Status = 'failed' | 'idle' | 'saved';export default function InlineMessageLive() { const [status, setStatus] = useState<Status>('idle'); return ( <Stack gap={4}> <Inline gap={2}> <Button onClick={() => setStatus('saved')} variant="outline"> Save prices </Button> <Button onClick={() => setStatus('failed')} variant="outline"> Lose connection </Button> </Inline> <InlineMessage live="polite" reserve tone="success"> {status === 'saved' ? 'Changes to 214 products are live.' : ''} </InlineMessage> <InlineMessage live="assertive" reserve tone="danger"> {status === 'failed' ? 'Price changes are not being saved.' : ''} </InlineMessage> </Stack> );}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.
import { Inline } from '@slotted/react/inline';import { InlineMessage } from '@slotted/react/inline-message';import { Stack } from '@slotted/react/stack';import { TextField } from '@slotted/react/text-field';export default function InlineMessageReserve() { return ( <Inline gap={4}> <Stack gap={2}> <TextField aria-label="Units, Rotterdam" defaultValue="120" /> <InlineMessage reserve tone="danger" /> <TextField aria-label="Reorder point, Rotterdam" defaultValue="40" /> </Stack> <Stack gap={2}> <TextField aria-label="Units, Antwerp" defaultValue="900" /> <InlineMessage reserve tone="danger"> Order at most 500 units at once. </InlineMessage> <TextField aria-label="Reorder point, Antwerp" defaultValue="60" /> </Stack> </Inline> );}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.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { InlineMessage, InlineMessageActions } from '@slotted/react/inline-message';export default function InlineMessageActionsExample() { const [quantity, setQuantity] = useState<number | null>(null); if (quantity !== null) { return ( <InlineMessage live="polite" size="md" tone="success"> Quantity set to {quantity}. </InlineMessage> ); } return ( <InlineMessage live="polite" size="md" tone="warning"> Order 4821 lists 240 units. Did you mean 24? <InlineMessageActions> <Button onClick={() => setQuantity(24)} variant="outline"> Use 24 </Button> <Button onClick={() => setQuantity(240)} variant="ghost"> Keep 240 </Button> </InlineMessageActions> </InlineMessage> );}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.
import { useId } from 'react';import { InlineMessage } from '@slotted/react/inline-message';import { Stack } from '@slotted/react/stack';import { TextField } from '@slotted/react/text-field';export default function InlineMessageWiring() { const messageId = useId(); return ( <Stack gap={2}> <TextField aria-errormessage={messageId} aria-label="EIN" defaultValue="12-345678" invalid /> <InlineMessage id={messageId} tone="danger"> The EIN has 8 digits and needs 9. </InlineMessage> </Stack> );}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'Defaultsecondary- 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'Defaultsm- 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'Defaultoff- 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'Defaultglyph- 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.
hideIconbooleanDefaultfalse- 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.
loadingbooleanDefaultfalse- 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.
reservebooleanDefaultfalse- 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.
idstringDefaultgenerated- 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
| Part | Element | Required | Purpose |
|---|---|---|---|
root | p, or the element render returns | Yes | The 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. |
prefix | span | No | The 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. |
icon | span | No | The 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. |
text | span | Yes | The 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. |
actions | div | No | The 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
| Token | Default |
|---|---|
--slotted-inline-message-actions-gap | var(--_column-gap) |
--slotted-inline-message-actions-offset | var(--slotted-space-2, 0.25rem) |
--slotted-inline-message-column-gap | var(--slotted-space-4, 0.5rem) |
--slotted-inline-message-font-family | var(--slotted-control-font-family, sans-serif) |
--slotted-inline-message-line-height | var(--slotted-line-height-md, 1.5) |
Theme tokens it reads
| Token | Default |
|---|---|
--slotted-border-width-thin | 1px |
--slotted-control-font-family | var(--slotted-font-family-sans) |
--slotted-control-font-size-md | comfortable 13px · compact 12px · dense 12px |
--slotted-control-font-size-sm | comfortable 12px · compact 12px · dense 12px |
--slotted-disabled-foreground | Set per scheme by the theme |
--slotted-duration-loop-fast | 700ms |
--slotted-line-height-md | 1.5 |
--slotted-radius-full | 9999px |
--slotted-space-2 | 0.25rem |
--slotted-space-4 | 0.5rem |
--slotted-text-box-edge | cap alphabetic |
--slotted-text-muted | Set per scheme by the theme |
--slotted-tone-accent-text | Set per scheme by the theme |
--slotted-tone-danger-text | Set per scheme by the theme |
--slotted-tone-info-text | Set per scheme by the theme |
--slotted-tone-success-text | Set per scheme by the theme |
--slotted-tone-warning-text | Set per scheme by the theme |