Skip to content

LoadingBar ​

A global loading progress bar at the top (or bottom) of the page, driven by an imperative API. Multiple start calls count concurrent sessions — only the last finish/error closes the bar. Supports incremental control, local containers, reverse/RTL, and lifecycle events.

Basic usage ​

Start & finish

Start loadingFinish now

Active sessions: false

loadingBar.start() auto-advances the progress (asymptotically approaching 90%); finish() fills the bar and fades it out.

Error state ​

Error & fallback

Simulate load failureError without start

Calling error() without a prior start is a fallback scenario: it skips the loading phase and closes directly in the error state (red + fade-out), so failures stay visible without flicker. Any error() in a batch decides the final state.

Session counting ​

Concurrent sessions

Start task AStart task BFinish one task

Active sessions: 0

Multiple start calls are counted; the bar advances once. Each completed session calls finish() once — only the last one closes the bar. The active count is displayed live (query it with loadingBar.getEl()?.sessions).

Position ​

Top / bottom

Top (default)Bottom

Local container ​

Local loading bar

Load inside container

to mounts the bar into a specific container (element / selector / function); it is positioned relative to that container and does not affect the global bar. The container must be a positioning context (e.g. position: relative), otherwise position: absolute resolves against the nearest positioned ancestor.

Incremental control ​

Incremental control & speed

StartAdvance 10Set 60%Back 10Advance speed:

Current progress: —

increment/decrement move the progress relatively (default random 0–10); set positions it exactly (clamped to 0–100). start(speed) or the speed attribute control the advance tick (ms per tick).

Reverse & RTL ​

Reverse / RTL

Reverse
Load in RTL container

reverse grows the bar from the inline end; in RTL it grows from the inline start (right side) by default. Layout uses logical properties (inset-inline-* / inset-block-*) throughout.

Lifecycle events ​

Events & active state

StartFinishError

Latest event: —

Lifecycle events fire on the bar element (oas-start / oas-finish / oas-error, bubbles + composed, reachable from document). Query the active state with loadingBar.active / isActive(), or grab the element with getEl() to attach listeners.

Clear ​

Clear

StartRemove loading bar

API ​

oas-loading-bar ​

Attributes ​

AttributeDescriptionTypeDefault
localLocal-mode marker (boolean): set automatically when the imperative API is given a to container; the component switches to absolute positioning inside that container. Does not accept a selector/element — the mount target is decided by the imperative to option——
positionPosition: top (default) / bottom——
reverseReverse direction (RTL progress flows right to left)——
speedBase advance speed (ms, default 200); start(speed) overridesstring200
statusCurrent status (activity query): the component only writes error at the error terminal state and removes the attribute otherwise (never writes loading/finish)string—

Methods ​

MethodSignatureDescription
startstart(speed?: number): voidStart a loading session: increments the concurrency count; the first session starts progress and dispatches oas-start
finishfinish(): voidComplete a session: decrements the concurrency count; only the last finish triggers the wrap-up
errorerror(): voidFailure wrap-up: decrements the concurrency count; any error in the batch decides the final state
incrementincrement(step?: number): voidAdvance progress by step manually (random 0–10 by default); clamped to 0–100
setset(percent: number): voidSet progress precisely (clamped to 0–100)
decrementdecrement(step?: number): voidRoll progress back by step manually (random 0–10 by default); clamped to 0–100

Events ​

EventDescription
oas-errorDispatched when error() finalizes in the error state, detail: { count: this.sessionCount }
oas-finishDispatched when finish() finalizes, detail: { count: this.sessionCount }
oas-startDispatched when the first session of a batch calls start() (subsequent start() calls of a concurrent batch do not re-dispatch), detail: { count: this.sessionCount }

CSS Variables ​

CSS VariableDefault
--oas-loading-bar-colorvar(--oas-color-primary)
--oas-loading-bar-error-colorvar(--oas-color-danger)
--oas-loading-bar-height3px
--oas-loading-bar-z-indexcalc(var(--oas-z-index-base, 0) + var(--oas-z-message, 1060))

target is a container element / CSS selector / function returning an element; it defaults to the nearest oas-app host or body.

The bar uses role="progressbar" with progress synced via aria-valuenow and the active state via aria-busy.

Released under the MIT OR Apache-2.0 License.