Feedback and overlays
Offline and update notices
Two notices for an installable web app, shown as a dark pill at the bottom of the screen. <kui-offline-notice> appears by itself while the device is offline. <kui-update-notice> offers to reload when a new version is ready, once kui.watchUpdates(registration) connects it to the service worker.
Examples
Put them in the page once
Both elements are empty until they have something to say. Place them at the end of the body. The words are the keyed offline, online and update words, in the language of the page.
// After the service worker is registered:
const registration = await navigator.serviceWorker.register('/sw.js');
kui.watchUpdates(registration);
// In sw.js: take the new version when the person presses Reload.
self.addEventListener('message', (e) => {
if (e.data?.type === 'skip-waiting') self.skipWaiting();
});HTML
<kui-offline-notice></kui-offline-notice>
<kui-update-notice></kui-update-notice>
<div class="kui-codeblock"><pre tabindex="0" aria-label="Script that connects the update notice"><code>// After the service worker is registered:
const registration = await navigator.serviceWorker.register('/sw.js');
kui.watchUpdates(registration);
// In sw.js: take the new version when the person presses Reload.
self.addEventListener('message', (e) => {
if (e.data?.type === 'skip-waiting') self.skipWaiting();
});</code></pre></div>
How they look
The same notices drawn in place with .kui-notice--inline. In the product they float at the bottom centre, above a tab bar if there is one.
You are offline. What you do is kept on this device.
You are back online.
A new version is ready.
Niste na mreži. Ono što radite čuva se na ovom uređaju.
HTML
<div class="kui-stack kui-gap-3">
<div class="kui-notice kui-notice--inline"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#wifi-off"></use></svg><span>You are offline. What you do is kept on this device.</span></div>
<div class="kui-notice kui-notice--inline"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#wifi"></use></svg><span>You are back online.</span></div>
<div class="kui-notice kui-notice--inline"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#refresh-cw"></use></svg><span>A new version is ready.</span><div class="kui-notice__actions"><button class="kui-button kui-button--sm" type="button">Not now</button><button class="kui-button kui-button--primary kui-button--sm" type="button">Reload</button></div></div>
<div class="kui-notice kui-notice--inline" lang="sr-Latn"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#wifi-off"></use></svg><span>Niste na mreži. Ono što radite čuva se na ovom uređaju.</span></div>
</div>
Classes and attributes
<kui-offline-notice>- Shows the offline notice while navigator.onLine is false, and “You are back online” for three seconds after.
<kui-update-notice>- Shows “A new version is ready” with Not now and Reload when a new service worker is waiting.
kui.watchUpdates(registration)- Connects a service worker registration to every update notice. Reload sends { type: "skip-waiting" } to the waiting worker and reloads the page once it takes over. The first install is not an update and shows nothing.
.kui-notice- The pill, fixed at the bottom centre.
.kui-notice__actions- The buttons of a notice, kept together; on a narrow screen they move under the sentence.
.kui-notice--inline- The pill in the flow of the page, for a settings page or this reference.
Keyboard
- Tab
- Reaches Not now and Reload in the update notice.
Accessibility
- Both elements are polite live regions (role="status"): the notice is read once when it appears, without moving focus.
- The pill uses the strongest text colour as background, so its text keeps contrast in both modes.
- Each notice has an icon and a sentence; nothing is said by colour.
- The update notice never reloads by itself, so nothing a person is typing is lost.
Do and do not
Do
- Keep work possible while offline and say so: the offline sentence does.
- Call kui.watchUpdates once, after registering the worker.
Do not
- Do not reload the page by itself when an update arrives.
- Do not show your own offline banner as well.