Loading overlay
Covers a form or panel with a spinner while it loads or saves, and keeps people from editing it meanwhile.
Example
<focsd-loading-overlay id="save-overlay" label="Saving changes"> <form class="stack"> <focsd-text-field label="Team name" value="Platform"></focsd-text-field> <focsd-textarea label="Release notes" value="Faster search and a new export option."></focsd-textarea> <focsd-button id="save-button" variant="action">Save</focsd-button> </form></focsd-loading-overlay>
<script type="module">const overlay = document.getElementById('save-overlay');const save = () => new Promise((done) => setTimeout(done, 1500)); // your save
// run() shows the overlay until save() finishes (or fails).document.getElementById('save-button').addEventListener('click', () => overlay.run(save));</script>Usage
Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.
<script type="module"> import '@focsd-dev/components/focsd-loading-overlay.js';</script>
<focsd-loading-overlay label="Saving changes">…</focsd-loading-overlay>import { LoadingOverlay } from '@focsd-dev/react';
export function Example() { return <LoadingOverlay label="Saving changes">…</LoadingOverlay>;}<script setup>import '@focsd-dev/components/focsd-loading-overlay.js';</script>
<template> <focsd-loading-overlay label="Saving changes">…</focsd-loading-overlay></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-loading-overlay.js';
// template<focsd-loading-overlay label="Saving changes">…</focsd-loading-overlay><script> import '@focsd-dev/components/focsd-loading-overlay.js';</script>
<focsd-loading-overlay label="Saving changes">…</focsd-loading-overlay>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
active | active | boolean | false |
label | label | string | — |
busy-on-submit | busyOnSubmit | boolean | false |
Methods
| Method | Description |
|---|---|
run(task) | Show the overlay while task runs: a function (called) or a promise. Resolves with its result;
the overlay goes away when it settles, also on failure. |
Slots
| Slot | Description |
|---|---|
(default) | The content to cover. |
indicator | Replaces the spinner: an image, an animation or a progress bar. |
label | Replaces the text under the indicator; plain text is also announced. Or set label. |
CSS parts
Style the inside of the component with ::part(), for example focsd-loading-overlay::part(region).
| Part | Description |
|---|---|
region | The wrapper around the content; `inert` and `aria-busy` while active. |
overlay | The cover shown while active; it takes focus from the content. |
spinner | The spinner in the overlay. |
text | The visible text in the overlay (`label`, or "Loading"). |
status | The visually hidden status region that announces loading and loaded. |
Accessibility
- While
active, the content isinert(no focus, no clicks, hidden from assistive technology) and markedaria-busy. - "Loading" (or
label) is announced when loading starts and "Loaded" when it ends, through a polite status region. When focus moves to the overlay, its name already says "Loading", so the status stays quiet until "Loaded". - An overlay that is already
activewhen it first renders neither announces nor moves focus; only later changes ofactivedo. - If focus was inside the content, it moves to the overlay while loading and comes back afterwards; if that element is gone, it goes to the first focusable element in the content. Focus elsewhere on the page is left alone.
- Use
labelto say what is happening ("Saving changes"); keep it short. For richer content, put an element withslot="label"inside (its text is announced), andslot="indicator"for your own image or animation in place of the spinner. - No glue code for the common cases:
run(save)shows it untilsave()settles, andbusy-on-submitturns it on when a form inside posts to the server. - In forced colors the overlay is an opaque system surface with an outline.
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.