DocsSearch & loading
Get started

Search Subtly documentation

Search by a task, helper name or framework.

Search & loading

loadingIndicator()

Avoid flashes from very short loading states.

Try the example

Load the report with a fast or slow connection. Both requests show a busy state immediately, but only the longer request displays the spinner after 200 ms.

Activity report

Choose a request speed.

Actual npm package · local demonstration

Add it to your project

  1. Copy the HTML. Place the markup inside the component where this behavior belongs. The preview’s visual classes are website styles; use your own design system.
  2. Connect the behavior. Copy the JavaScript tab and call its exported mount(element) after your component’s elements exist. Replace simulated delays and data operations with your own application code.
  3. Clean up. Call the returned cleanup when the component unmounts. It aborts the example’s listeners and releases the helper’s timers, observers or state.

API and lifecycle

Provide render(show) for a loading region. start() waits before showing the visual indicator; stop() enforces a minimum visible duration to avoid flashes. Defaults: 200 ms delay and 300 ms minimum visibility.

Interface
render, delay, minVisible; start/stop/destroy
Lifecycle
Use one instance per loading region. destroy() clears timers and hides the visual indicator when the region is removed.

Accessibility and safety

Implementation notes

Initialize after the DOM is available. Keep native controls and keyboard interactions intact; release listeners and timers on unmount.

aria-busy must track the real request state rather than the spinner's visual delay. Provide meaningful status text when a task needs an explanation.

What to check

Compare fast and slow requests. Check that fast work does not flash a spinner, and that accessibility state clears when the request finishes.