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 withmessage - Dispatches
oas-offline/oas-onlineonly when the state actually changes role="status"+aria-live="polite"; while online the host isdisplay: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)
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:
const offline = document.querySelector('oas-offline')
offline.addEventListener('oas-offline', () => console.info('offline'))
offline.addEventListener('oas-online', () => console.info('online'))API
oas-offline
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
message | Copy override; defaults to i18n offline.message | string | — |
variant | Presentation: bar (default, fixed to the top of the viewport) / block (in-flow notice block) | string | — |
Events
| Event | Description |
|---|---|
oas-offline | Dispatched when entering the offline state (only on real state changes) |
oas-online | Dispatched when the network recovers (only on real state changes) |
CSS Variables
| CSS Variable | Description | Default |
|---|---|---|
--oas-offline-bg | Notice background (defaults to the danger semantic color) | var(--oas-color-danger) |
--oas-offline-color | Notice text color (defaults to --oas-color-text-on-danger) | var(--oas-color-text-on-danger) |