Skip to content

Offline ​

Listens to the browser online / offline events and keeps the network state in sync: a notice appears when offline and disappears automatically on reconnect. The first frame is decided directly from navigator.onLine, so there is no "online first, offline after" flash.

  • variant="bar" (default) is fixed to the top of the viewport and spans the width; variant="block" stays in the document flow
  • Copy defaults to the i18n key offline.message; override it with message
  • Dispatches oas-offline / oas-online only when the state actually changes
  • role="status" + aria-live="polite"; while online the host is display:none, leaving no residue in the accessibility tree

Basic Usage ​

The default bar is fixed to the top. The interactive demo below uses the block variant in the document flow and temporarily shadows navigator.onLine to simulate offline / reconnect. The override persists for the whole page session — navigating to other docs pages within the SPA keeps showing the offline state (other example instances appear as well); only a full reload (F5) restores it. For debugging demos only; production should rely on real browser network events.

Simulate offline / reconnect (block variant)

Simulate offlineSimulate reconnectNot triggered yet

Custom Copy ​

message overrides the default copy

The example is invisible while online; switch DevTools to Offline or use the simulation buttons above to see it (only one notice renders per page — this block just demonstrates the attribute).

Fixed Bar ​

variant="bar" is fixed to the top of the viewport and spans the width — suitable for full-screen pages without a navbar:

bar variant (always mounted; invisible while online)

The bar covers the top of the viewport when actually offline; this block is online, so it is invisible.

Events ​

oas-offline / oas-online are bubbles + composed, so the host can listen directly:

js
const offline = document.querySelector('oas-offline')
offline.addEventListener('oas-offline', () => console.info('offline'))
offline.addEventListener('oas-online', () => console.info('online'))

API ​

oas-offline ​

Attributes ​

AttributeDescriptionTypeDefault
messageCopy override; defaults to i18n offline.messagestring—
variantPresentation: bar (default, fixed to the top of the viewport) / block (in-flow notice block)string—

Events ​

EventDescription
oas-offlineDispatched when entering the offline state (only on real state changes)
oas-onlineDispatched when the network recovers (only on real state changes)

CSS Variables ​

CSS VariableDescriptionDefault
--oas-offline-bgNotice background (defaults to the danger semantic color)var(--oas-color-danger)
--oas-offline-colorNotice text color (defaults to --oas-color-text-on-danger)var(--oas-color-text-on-danger)

Released under the MIT OR Apache-2.0 License.