<!-- index: /slotted/llms.txt -->
# loading-overlay

`data-ui="loading-overlay"` · Veil and indicator over a loading region.

## Import

```tsx
import { LoadingOverlay, LoadingOverlayDefaultsProvider } from '@slotted/react';
```

## Minimal example

Example

```tsx
import { useState } from 'react';

import { Button } from '@slotted/react/button';
import { Card, CardBody, CardHeader } from '@slotted/react/card';
import { Field, FieldLabel } from '@slotted/react/field';
import { Inline } from '@slotted/react/inline';
import { LoadingOverlay } from '@slotted/react/loading-overlay';
import { Stack } from '@slotted/react/stack';
import { TextField } from '@slotted/react/text-field';
import { Heading } from '@slotted/react/typography';

export default function LoadingOverlayBasic() {
  const [saving, setSaving] = useState(false);

  const save = () => {
    setSaving(true);
    setTimeout(() => setSaving(false), 2500);
  };

  return (
    <LoadingOverlay loading={saving} messages={{ label: 'Saving the customer' }}>
      <Card>
        <CardHeader>
          <Heading level={3} size="md">
            Customer profile
          </Heading>
        </CardHeader>
        <CardBody>
          <Stack gap={4}>
            <Field>
              <FieldLabel>Company</FieldLabel>
              <TextField defaultValue="Northwind Traders" />
            </Field>
            <Inline>
              <Button onClick={save}>Save customer</Button>
            </Inline>
          </Stack>
        </CardBody>
      </Card>
    </LoadingOverlay>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | div | yes |
| `announcement` | span | yes |
| `content` | div | no |
| `scrim` | div | yes |
| `panel` | div | no |
| `indicator` | span | no |
| `label` | span | no |
| `description` | span | no |
| `cancel` | button | no |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `loading` | `boolean` | true | LoadingOverlay | Whether the data is still on its way. The consumer’s own fact: the overlay never moves it, so there is no controlled and uncontrolled pair |
| `scope` | `'region' \| 'page'` | region | LoadingOverlay | What is covered. region is the box this element wraps; page is the whole viewport, portalled and modal |
| `veil` | `'wash' \| 'blur' \| 'none'` | wash | LoadingOverlay | How the covered content is obscured. none blocks exactly as much and dims nothing |
| `size` | `'sm' \| 'md' \| 'lg'` | md | LoadingOverlay | The panel’s step: its padding, its type, and the size of the default mark |
| `live` | `'polite' \| 'off'` | polite | LoadingOverlay | Whether the overlay announces the wait at all. off is for a page that already says it elsewhere |
| `messages` | `Partial<LoadingOverlayMessages>` | — | LoadingOverlay | Words laid over the language in force, key by key: the short line (label), painted in the panel and announced once, and the cancel control’s words (cancel) |
| `loadedLabel` | `string` | — | LoadingOverlay | What a screen reader hears when the wait ends. Silent unless set, so one wait says one thing |
| `description` | `ReactNode` | — | LoadingOverlay | The second line, for what the first cannot hold. Painted, never announced |
| `cancellable` | `boolean` | false | LoadingOverlay | Renders the control that asks to stop, and binds Escape to it |
| `cancelLabel` | `ReactNode` | — | LoadingOverlay | What that control says, in place of the catalog’s cancel |
| `delay` | `number` | 0 | LoadingOverlay | Milliseconds the wait must last before anything is painted |
| `minDuration` | `number` | 0 | LoadingOverlay | Milliseconds a layer that did appear is held before it is withdrawn |
| `container` | `HTMLElement \| null` | — | LoadingOverlay | Where a page-scoped layer is portalled. Defaults to the document body; meaningless for a region |
| `children` | `ReactNode` | — | LoadingOverlay | Covered rather than replaced: the content keeps its geometry, stays measured, and goes inert while the layer blocks |
| `indicator` | `ReactNode` | — | LoadingOverlay | Replaces the mark. A determinate wait passes progress-indicator’s own ProgressBar with a value |
| `render` | `(props) => ReactNode` | — | LoadingOverlay | Substitutes the region’s element. Every data attribute, the ref and aria-busy are handed to it |
| `renderCancel` | `(props) => ReactNode` | — | LoadingOverlay | Substitutes the control. The overlay’s own control paint is written :not([data-ui]), so a Button here keeps its own |
| `ref` | `Ref<HTMLDivElement>` | — | LoadingOverlay | Reaches the region element; the props are that element’s, extended |
| `LoadingOverlayDefaultsProvider` | `LoadingOverlayDefaults` | — | Application | Sets veil, size, live, loadedLabel, delay and minDuration once for everything below it; a prop still wins |

## Events

| Name | Payload | When |
| --- | --- | --- |
| `onCancel` | `{ reason: "dismiss" \| "escape"; source: Event }` | The reader presses the control or the Escape key. The overlay commits nothing — it does not lower loading and does not hide itself — because the operation has not stopped until the application has stopped it. |
| `onReveal` | `void` | The covered content is reachable again, which is later than loading turning false whenever minDuration is still holding the layer. It is the moment an application moves focus on. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `scope` | `region`, `page` | `region` |
| `veil` | `wash`, `blur`, `none` | `wash` |
| `size` | `sm`, `md`, `lg` | `md` |
| `live` | `polite`, `off` | `polite` |

## Rules

- The covered content carries inert while the layer blocks, which takes it out of the tab order and out of the accessibility tree. A covered control is neither focusable nor announced, so the reader does not reach a field the wait has made unsafe to edit.
- The region carries aria-busy="true" while it waits, which is the platform’s own answer: ARIA 1.2 asks an author to set it on the region until it is finished loading. Page scope writes it nowhere, because the busy region would be the document root and LoadingOverlay owns no part of it.
- One overlay is one announcement. A visually-hidden role="status" holds the label while waiting and is emptied afterwards, and emptying a live region announces nothing, so a wait says one thing. The two painted lines carry aria-hidden, so the same sentence is not heard twice.
- Focus is read before the content goes inert. If it was inside, it moves to the control or to the panel itself — the container destination the APG advises for content that must be read before it is operated — and returns to where it came from when the wait ends. Focus that was elsewhere is never moved: a background save does not take the caret out of another form.
- There is no APG pattern for a loading overlay: the pattern index holds none for a busy region or a blocking layer, and claiming the Dialog pattern would import aria-modal and a close affordance into something that is neither. Page scope makes the rest of the document inert instead, which is what ARIA 1.2 asks of a modal element, and writes no aria-modal because that property inherits only into dialog and alertdialog.
- Escape is bound only while a control exists for it to ask. A key that appears to do something and does nothing is worse than a key nobody bound, and an overlay with nothing to cancel has nothing for the key to ask for.

## Tokens

`--slotted-border-subtle`, `--slotted-border-width-thin`, `--slotted-control-border-color`, `--slotted-control-border-width`, `--slotted-control-font-size-lg`, `--slotted-control-font-size-md`, `--slotted-control-font-size-sm`, `--slotted-control-height-lg`, `--slotted-control-height-md`, `--slotted-control-height-sm`, `--slotted-control-padding-inline-sm`, `--slotted-control-radius`, `--slotted-disabled-border`, `--slotted-disabled-foreground`, `--slotted-duration-medium`, `--slotted-duration-short`, `--slotted-easing-enter`, `--slotted-easing-exit`, `--slotted-easing-standard`, `--slotted-focus-ring-color`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-weight-medium`, `--slotted-line-height-lg`, `--slotted-line-height-md`, `--slotted-line-height-sm`, `--slotted-loading-overlay-blur`, `--slotted-loading-overlay-inset`, `--slotted-loading-overlay-measure`, `--slotted-loading-overlay-radius`, `--slotted-loading-overlay-scrim`, `--slotted-loading-overlay-surface`, `--slotted-radius-md`, `--slotted-scrim`, `--slotted-shadow-lg`, `--slotted-space-3`, `--slotted-space-4`, `--slotted-space-5`, `--slotted-space-6`, `--slotted-space-7`, `--slotted-surface-raised`, `--slotted-text`, `--slotted-text-muted`, `--slotted-tone-secondary-subtle-active`, `--slotted-tone-secondary-subtle-hover`, `--slotted-z-index-overlay`

## Examples

See [loading-overlay.examples.md](./loading-overlay.examples.md).
