Skip to content
Slotted

Loading overlay

Covers a region, or the whole page, while a wait the application owns runs, and keeps the covered content in place and out of reach.

Customer profile

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 { LoadingOverlay, LoadingOverlayDefaultsProvider } from '@slotted/react';

Covering a region

The overlay wraps the content it covers. The content stays in the document and keeps its geometry, so nothing around it moves when the layer appears. While the layer blocks, the content is inert: its controls leave the tab order and the accessibility tree, and the region carries aria-busy. loading is the application’s own fact and defaults to true, so set it from the state of the request. Focus that was inside the content moves into the panel and returns to where it came from when the wait ends; focus that was elsewhere does not move. Press Save customer in the lead example: the card is covered for 2.5 seconds.

Veil

veil sets how the covered content is obscured. wash draws the theme’s scrim, blur adds a backdrop filter so the text stops being legible, and none blocks exactly as much and dims nothing, for a wait short enough that a wash would read as a flash. Each card here shows its own value as the description.

Refreshing balances

Open invoices

14 invoices, $48,210.00
Refreshing balances

Overdue balance

3 customers, $6,940.50
Refreshing balances

Pending refunds

2 orders, $318.00

Sizes

size sets the mark, the two lines of text and the padding of the panel to one step: sm for dense regions, md for most cards, lg for sparse ones. The panel also follows the width of the region: below 220 px it keeps the mark and drops the two lines, and the announcement still carries the sentence.

Reconciling

Bank statement

312 lines, 18 unmatched
Reconciling

Card payouts

41 payouts, 2 on hold
Reconciling

Supplier invoices

27 invoices, 5 due this week

Page scope

scope="page" covers the whole viewport. The layer is portalled, every sibling of the portal root becomes inert, and the document scroll is locked. Tab wraps inside the layer. Use it only when partial interaction would be unsafe, such as closing an accounting period, and not for a row that is saving. The region carries no aria-busy in this scope. Press Close March period: the wait ends after 4 seconds, or sooner with Cancel.

Cancelling

cancellable renders the control that asks to stop and binds Escape to it while focus is inside the layer. The request carries a reason, dismiss for the press and escape for the key, and commits nothing: the overlay stays until the application aborts its work and sets loading to false. The handler is onCancel in React and the cancel output in Angular. Start the import, press Tab to reach the control, then stop the import with the control or with Escape.

Price list

4 812 rows, last updated 12 Nov.
No import has run yet.

Timing

delay is how long the wait must last before anything is painted, so a response that arrives sooner draws nothing. minDuration is how long a painted layer is held, so it does not vanish a few frames after it appeared. Both default to zero. onReveal in React and the reveal output in Angular fire when the covered content is reachable again, which is later than loading turning false whenever minDuration is still holding the layer. The 100 ms lookup draws no layer. The 500 ms lookup draws one after 300 ms and holds it until 600 ms after it appeared.

Exchange rates

1 EUR = 1.08 USD, 1 GBP = 1.27 USD.
Layers drawn: 0

Indicator

The mark is a slot. The default is the contained loader of progress-indicator. For a wait that reports how much is done, pass a ProgressBar with its own value: the indicator prop in React, an element with slLoadingOverlayIndicator projected into the overlay in Angular. The overlay holds no progress value of its own. Start the upload: the bar advances every 400 ms.

Carrier manifest

Pickup list for 14 Nov, 38 shipments.

Labels

messages.label is the short line. It is painted in the panel and announced once. description is a second line for what the first cannot hold; it is painted and never announced. messages.cancel replaces the words of the cancel control. The panel wraps a long sentence and keeps its own measure, and the announcement holds the sentence whole.

Reconciling the period entries against the bank statement

March close

1 204 entries, 37 without a bank match.

Announcements

A screen reader hears one sentence when the wait begins: the role="status" element holds messages.label, and the painted lines are aria-hidden so the sentence is not heard twice. The wait ends in silence unless loadedLabel is set, in which case that sentence is announced. live="off" removes the announcement for a page that already says the wait elsewhere.

Prices saved

Price list

Announces the wait and the result.

Stock levels

Announces nothing: the page says it elsewhere.

Defaults

veil, size, live, loadedLabel, delay and minDuration are set once for everything below a provider: LoadingOverlayDefaultsProvider in React, provideLoadingOverlayDefaults in Angular. A prop or input on an overlay wins over the provider.

Open orders

Takes the blur and the small step from the provider.

Returns

Keeps the small step and sets its own veil.

Substituting the parts

The region and the cancel control can be elements the page already has. In React, render receives the props of the region and returns its element, and renderCancel does the same for the control. In Angular the selector is a bare attribute, so the region is the element it sits on, and slLoadingOverlayCancel marks a projected control as the cancel part. The paint of the control is written :not([data-ui]), so a component that carries its own data-ui keeps its own paint, and on a Button the element stays the root of the button. Focus still lands on it when the overlay opens over a focused field.

Syncing the warehouse feed

Warehouse feed

Lisbon and Rotterdam, 6 docks.Last sync at 09:40, 212 pallets received.Next sync at 10:10.

Accessibility

KeyEffectFocus
Tableaves the layer for the next tabbable element after the region, because only this region is blockedthe next tabbable element outside the root
Tabwraps inside the layer, because everything outside it is inertthe next tabbable element inside the layer
Shift+Tabwraps inside the layerthe previous tabbable element inside the layer
Escapeasks to cancel; the family commits nothing and the consumer's own abort ends the waitunchanged
Enter or Spacethe platform's own button activation, asking to cancelunchanged
  • 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.

API

LoadingOverlay

Props

loadingbooleanDefault true
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'Default region
What is covered. region is the box this element wraps; page is the whole viewport, portalled and modal
veil'wash' | 'blur' | 'none'Default wash
How the covered content is obscured. none blocks exactly as much and dims nothing
size'sm' | 'md' | 'lg'Default md
The panel’s step: its padding, its type, and the size of the default mark
live'polite' | 'off'Default polite
Whether the overlay announces the wait at all. off is for a page that already says it elsewhere
messagesPartial<LoadingOverlayMessages>
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)
loadedLabelstring
What a screen reader hears when the wait ends. Silent unless set, so one wait says one thing
descriptionReactNode
The second line, for what the first cannot hold. Painted, never announced
cancellablebooleanDefault false
Renders the control that asks to stop, and binds Escape to it
cancelLabelReactNode
What that control says, in place of the catalog’s cancel
delaynumberDefault 0
Milliseconds the wait must last before anything is painted
minDurationnumberDefault 0
Milliseconds a layer that did appear is held before it is withdrawn
containerHTMLElement | null
Where a page-scoped layer is portalled. Defaults to the document body; meaningless for a region

Events

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

Composition

childrenReactNode
Covered rather than replaced: the content keeps its geometry, stays measured, and goes inert while the layer blocks
indicatorReactNode
Replaces the mark. A determinate wait passes progress-indicator’s own ProgressBar with a value
render(props) => ReactNode
Substitutes the region’s element. Every data attribute, the ref and aria-busy are handed to it
renderCancel(props) => ReactNode
Substitutes the control. The overlay’s own control paint is written :not([data-ui]), so a Button here keeps its own
refRef<HTMLDivElement>
Reaches the region element; the props are that element’s, extended
LoadingOverlayDefaultsProviderLoadingOverlayDefaults
On ApplicationSets veil, size, live, loadedLabel, delay and minDuration once for everything below it; a prop still wins

Parts

PartElementRequiredPurpose
rootdivYesThe region. Carries aria-busy while the layer blocks, and is the containing block the layer is placed in. Under scope="page" it is the fixed layer itself, portalled.
announcementspanYesThe one visually-hidden role="status" per overlay. A child of the root and never of the layer, so the sentence it holds is not deleted at the moment it has something to say.
contentdivNoThe covered content, made inert while the layer blocks. display: contents, so a covered grid keeps its tracks. Absent under scope="page", where what is covered is the application.
scrimdivYesThe wash, the one-cell grid that centers the panel, and the query container. In the document for the life of the overlay, so both directions of the fade are transitions.
paneldivNoThe box the reader reads. A column in a tall region, a bar in a short one, and the mark alone in a small one. Mounted while the layer is painted and held through its exit.
indicatorspanNoThe mark. Holds progress-indicator's contained loader by default; the indicator prop replaces it with anything, including a determinate ProgressBar.
labelspanNoThe short line. Painted and never announced from here: the announcement above holds the same sentence, and a wait should be heard once.
descriptionspanNoThe second line, for what the first cannot hold. Rendered only when given.
cancelbuttonNoAsks to stop. Rendered when cancellable is set, and the only thing in the layer that takes focus. Escape is bound only while it exists.

Theming

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

Loading overlay tokens

TokenDefault
--slotted-loading-overlay-blur3px
--slotted-loading-overlay-insetvar(--slotted-space-4, 0.5rem)
--slotted-loading-overlay-measure18rem
--slotted-loading-overlay-radiusvar(--slotted-radius-md, 6px)
--slotted-loading-overlay-scrimvar(--slotted-scrim, Canvas)
--slotted-loading-overlay-surfacevar(--slotted-surface-raised, Canvas)

Theme tokens it reads

TokenDefault
--slotted-border-subtleSet per scheme by the theme
--slotted-border-width-thin1px
--slotted-control-border-colorSet per scheme by the theme
--slotted-control-border-widthvar(--slotted-border-width-thin)
--slotted-control-font-size-lgcomfortable 14px · compact 13px · dense 12px
--slotted-control-font-size-mdcomfortable 13px · compact 12px · dense 12px
--slotted-control-font-size-smcomfortable 12px · compact 12px · dense 12px
--slotted-control-height-lgcomfortable 38px · compact 32px · dense 30px
--slotted-control-height-mdcomfortable 34px · compact 28px · dense 26px
--slotted-control-height-smcomfortable 30px · compact 26px · dense 24px
--slotted-control-padding-inline-smcomfortable 10px · compact 8px · dense 6px
--slotted-control-radiusvar(--slotted-radius-sm)
--slotted-disabled-borderSet per scheme by the theme
--slotted-disabled-foregroundSet per scheme by the theme
--slotted-duration-medium200ms
--slotted-duration-short120ms
--slotted-easing-entercubic-bezier(0.05, 0.7, 0.1, 1)
--slotted-easing-exitcubic-bezier(0.3, 0, 0.8, 0.15)
--slotted-easing-standardcubic-bezier(0.2, 0, 0, 1)
--slotted-focus-ring-colorSet per scheme by the theme
--slotted-focus-ring-offsetvar(--slotted-border-width-thick)
--slotted-focus-ring-widthvar(--slotted-border-width-thick)
--slotted-font-weight-medium500
--slotted-line-height-lg1.5
--slotted-line-height-md1.5
--slotted-line-height-sm1.45
--slotted-radius-md6px
--slotted-scrimSet per scheme by the theme
--slotted-shadow-lgSet per scheme by the theme
--slotted-space-30.375rem
--slotted-space-40.5rem
--slotted-space-50.75rem
--slotted-space-61rem
--slotted-space-71.25rem
--slotted-surface-raisedSet per scheme by the theme
--slotted-textSet per scheme by the theme
--slotted-text-mutedSet per scheme by the theme
--slotted-tone-secondary-subtle-activeSet per scheme by the theme
--slotted-tone-secondary-subtle-hoverSet per scheme by the theme
--slotted-z-index-overlay1000