<!-- index: /slotted/llms.txt -->
# inline-message

`data-ui="inline-message"` · The hint or error of one field; a region uses alert.

## Import

```tsx
import {
  InlineMessage,
  InlineMessageActions,
  InlineMessageDefaultsProvider,
} from '@slotted/react';
```

## Minimal example

Example

```tsx
import { InlineMessage } from '@slotted/react/inline-message';

export default function InlineMessageBasic() {
  return <InlineMessage tone="danger">Enter the tax ID printed on the invoice.</InlineMessage>;
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | p, or the element render returns | yes |
| `prefix` | span | no |
| `icon` | span | no |
| `text` | span | yes |
| `actions` | div | no |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `tone` | `'accent' \| 'secondary' \| 'info' \| 'success' \| 'warning' \| 'danger'` | secondary | InlineMessage | 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'` | sm | InlineMessage | 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'` | off | InlineMessage | 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'` | glyph | InlineMessage | 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. |
| `prefix` | `string` | — | InlineMessage | 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. |
| `hideIcon` | `boolean` | false | InlineMessage | Draws no mark at all. The severity word stays, because it is what a reader hears rather than what a reader sees. |
| `icon` | `ReactNode` | — | InlineMessage | Replaces the tone’s mark, keeping its box, its size and its place on the first line. Angular projects an element carrying slInlineMessageIcon instead. |
| `loading` | `boolean` | false | InlineMessage | The message is waiting for something: the mark becomes a ring turning at the same duration Button’s does, and stopping under reduced motion. |
| `disabled` | `boolean` | — | InlineMessage | Unstated rather than false, so a Field around the message can answer it. Stated, it wins: the ink is muted and the ring stops. |
| `reserve` | `boolean` | false | InlineMessage | 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. |
| `id` | `string` | generated | InlineMessage | What aria-describedby or aria-errormessage points at. InlineMessage generates one from useId when the page states none, so the element is always addressable. |
| `render` | `(props) => ReactNode` | — | InlineMessage | 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. |
| `ref` | `Ref<HTMLParagraphElement>` | — | InlineMessage | 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 }` | — | a subtree | Sets the axes once, and the table of severity words, merged over the shipped one so a single word can be replaced alone. |
| `InlineMessageActions` | `component` | — | InlineMessage | Holds the answers the message offers, after its sentence. The buttons inside take the size of the message. |
| `children` | `ReactNode` | — | InlineMessage | 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. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `tone` | `accent`, `secondary`, `info`, `success`, `warning`, `danger` | `secondary` |
| `size` | `sm`, `md` | `sm` |
| `mark` | `glyph`, `dot`, `none` | `glyph` |
| `live` | `off`, `polite`, `assertive` | `off` |

## Rules

- 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.

## Tokens

`--slotted-border-width-thin`, `--slotted-control-font-family`, `--slotted-control-font-size-md`, `--slotted-control-font-size-sm`, `--slotted-disabled-foreground`, `--slotted-duration-loop-fast`, `--slotted-inline-message-actions-gap`, `--slotted-inline-message-actions-offset`, `--slotted-inline-message-column-gap`, `--slotted-inline-message-font-family`, `--slotted-inline-message-line-height`, `--slotted-line-height-md`, `--slotted-radius-full`, `--slotted-space-2`, `--slotted-space-4`, `--slotted-text-box-edge`, `--slotted-text-muted`, `--slotted-tone-accent-text`, `--slotted-tone-danger-text`, `--slotted-tone-info-text`, `--slotted-tone-success-text`, `--slotted-tone-warning-text`

## Examples

### Playground

One message with every axis on it, driven by the controls below the canvas. Change the tone and both the mark and the word a screen reader hears change with it.

Excerpt — not a complete module

```tsx
<InlineMessage tone="danger">Enter a valid EIN to continue.</InlineMessage>;
```

### What the message is about

Three severities, two tones for information, and help. secondary is help: no mark, no severity word, and the neutral muted ink rather than a tone’s louder label color.

Example

```tsx
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>
  );
}
```

### The step the message sits at

sm sits beside a compact field and md beside a large field. Both read the control scales, so switching the toolbar to dense shrinks them with the rows around them.

Example

```tsx
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>
  );
}
```

### A message that is still waiting

The mark becomes a ring turning in the same box, so the wait becomes its answer with no geometry moving. Under reduced motion the ring stops rather than slows.

Example

```tsx
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>
  );
}
```

### Pointing a control at the message

The three attributes that make an error reach a reader: aria-invalid on the control, aria-errormessage at the message’s id, and an id InlineMessage generates when the page states none.

Example

```tsx
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>
  );
}
```

### What a reader hears, and when

off by default, because a message already on the page when it loads is announced by nothing. Press the button and the message arrives while the reader is elsewhere, which is what polite is for.

Example

```tsx
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

Both columns render the message unconditionally; only the right one has something to say. The two second fields sit at the same height, because the empty message keeps its line and draws nothing in it.

Example

```tsx
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>
  );
}
```

### Content you write

A German compound over three lines, a container digest with no break opportunity, a sentence carrying a link, and the page’s own artwork — the mark stays on the first line in all four.

Excerpt — not a complete module

```tsx
<InlineMessage tone="secondary">
  We accept credit card, ACH transfer and Zelle. <Link href="/fees">View fees</Link>
</InlineMessage>;
```

### Composition and escape hatches

The provider translates the severity words once, render substitutes the element for a list of failures, and icon replaces the mark while keeping its box and its place.

Excerpt — not a complete module

```tsx
<InlineMessageDefaultsProvider prefixes={{ danger: 'Error:', warning: 'Attention:' }}>
  <App />
</InlineMessageDefaultsProvider>;

<InlineMessage icon={<ShieldIcon />} render={(props) => <div {...props} />}>
  Two-step verification protects this account.
</InlineMessage>;
```

### What a reader hears before the message

Turn a screen reader on and read the three rows: the severity is a word, not only a color and a silhouette, and it is the same word wherever the message is announced.

Excerpt — not a complete module

```tsx
// Heard as “Error: Enter a valid EIN.”
<InlineMessage tone="danger">Enter a valid EIN.</InlineMessage>;

// One message says its own word; the empty string removes it entirely.
<InlineMessage prefix="Error:" tone="danger" />;
<InlineMessage prefix="" tone="danger" />;
```

### actions.tsx

Example

```tsx
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>
  );
}
```

### marks.tsx

Example

```tsx
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>
  );
}
```

### prefix.tsx

Example

```tsx
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.tsx

Example

```tsx
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>
  );
}
```
