Skip to main content

This is a draft (version 0.5.0). The National Information Technology Agency (NITA) plans to make GGDS official guidance for government websites after independent accessibility testing. What this means

Ghana Government Design System Design system for Government of Ghana websites – home Search

Forms

Timeout warning

Warns people before they are signed out for being inactive, and lets them stay signed in with one button.

When to use

  • On every page of a service where people are signed in and are signed out after a time without activity.

When not to use

  • On pages without a time limit. If you can, do not sign people out at all: keep their answers instead.

How to use

  • Add the dialog to every signed-in page, with data-ggds-module="timeout-warning" and:
    • data-ggds-timeout: seconds of inactivity before you sign people out (the same as your server's session);
    • data-ggds-warn: seconds before that to warn them, at least 120;
    • data-ggds-keep-alive: an address on your website that extends the session when the script requests it, and fails or redirects once the session has ended (the script then goes to the sign-out page);
    • data-ggds-sign-out: where to go when time runs out, a page that says they have been signed out and that their answers are saved.
  • "Stay signed in" extends the session and closes the warning. "Sign out" goes to your sign-out address.
  • The time in the message can be translated: data-ggds-minutes-one, data-ggds-minutes-other, data-ggds-seconds-one and data-ggds-seconds-other, with {count} for the number.

Accessibility

What GGDS does

  • People get at least 2 minutes' warning and can extend the time with one button (WCAG 2.2.1, timing adjustable).
  • Screen readers read the whole message when the warning opens. The countdown on screen updates every second, but screen readers hear the message again only each minute, then at 30 and 10 seconds, so it does not talk over them.
  • The warning is a dialog: focus moves to "Stay signed in", and Escape also keeps them signed in.
  • Every tab of your website shares one deadline, so a tab left open never signs people out while they work in another.

What you need to do

  • Extend the session on every page people load, as the warning counts from each page (in Django, SESSION_SAVE_EVERY_REQUEST = True).
  • Save people's answers before you sign them out, and say so on the signed-out page.
  • Match data-ggds-timeout to the server, or people will be signed out before the warning.

Example: The warning, as it appears

Open this example on its own page

HTML code for “The warning, as it appears”
HTML
<p>The warning opens by itself 2 minutes before the end of the session. Here it opens after 3 seconds, so you can see it.</p>
<dialog class="ggds-dialog ggds-timeout-warning" id="timeout-warning" aria-labelledby="timeout-warning-title" aria-describedby="timeout-warning-message" data-ggds-module="timeout-warning" data-ggds-timeout="123" data-ggds-warn="120" data-ggds-keep-alive="#keep-alive" data-ggds-sign-out="#signed-out">
  <h2 class="ggds-dialog__title" id="timeout-warning-title">You will be signed out soon</h2>
  <div class="ggds-dialog__body">
    <p id="timeout-warning-message">To protect your information, we will sign you out in <span class="ggds-timeout-warning__time">2 minutes</span>.</p>
    <p class="ggds-visually-hidden" aria-live="polite"></p>
  </div>
  <div class="ggds-dialog__actions">
    <button class="ggds-button" type="button" data-ggds-timeout-continue>Stay signed in</button>
    <a href="#signed-out">Sign out</a>
  </div>
</dialog>
JSX (React)
<>
  <p>The warning opens by itself 2 minutes before the end of the session. Here it opens after 3 seconds, so you can see it.</p>
  <dialog className="ggds-dialog ggds-timeout-warning" id="timeout-warning" aria-labelledby="timeout-warning-title" aria-describedby="timeout-warning-message" data-ggds-module="timeout-warning" data-ggds-timeout="123" data-ggds-warn="120" data-ggds-keep-alive="#keep-alive" data-ggds-sign-out="#signed-out">
    <h2 className="ggds-dialog__title" id="timeout-warning-title">You will be signed out soon</h2>
    <div className="ggds-dialog__body">
      <p id="timeout-warning-message">To protect your information, we will sign you out in <span className="ggds-timeout-warning__time">2 minutes</span>.</p>
      <p className="ggds-visually-hidden" aria-live="polite"></p>
    </div>
    <div className="ggds-dialog__actions">
      <button className="ggds-button" type="button" data-ggds-timeout-continue>Stay signed in</button>
      <a href="#signed-out">Sign out</a>
    </div>
  </dialog>
</>

Use it

Stylesheet
ggds.css includes it. To load only the parts you use: core.css, then components/dialog.css (0.6 KB with gzip, minified).
JavaScript
Needed: @ggds/js counts the inactive time, opens the warning, counts down, extends the session with "Stay signed in" and goes to the sign-out page when time runs out.

HTML

Copy the HTML under each example above. It works in any website.

Astro

With @ggds/astro:

JavaScript
import TimeoutWarning from '@ggds/astro/TimeoutWarning.astro';

---
import TimeoutWarning from '@ggds/astro/TimeoutWarning.astro';
---
<TimeoutWarning timeout={1200} keepAlive="/session/keep-alive/" signOut="/signed-out/" />

React and Next.js

With @ggds/react:

JavaScript
import { TimeoutWarning } from '@ggds/react';

{/* On every signed-in page: 20 minutes, warned 2 minutes before */}
<TimeoutWarning timeout={1200} keepAlive="/session/keep-alive/" signOut="/signed-out/" />

Django

With ggds-django ({% load ggds %}):

Django template
{% load ggds %}
{% ggds_timeout_warning timeout=1200 keep_alive="/session/keep-alive/" sign_out="/signed-out/" %}

Classes and states

Classes for timeout warning
ClassWhat it does
.ggds-timeout-warningOn the dialog: the timeout warning. data-ggds-timeout, -warn, -keep-alive and -sign-out configure it.
.ggds-timeout-warning__timeThe time left, updated every second.

Accessibility tests

Automated, on every change

These run each time GGDS changes. A change that fails one is not accepted.

  • WCAG 2.2 A and AA rules (axe), at desktop and phone widths, on every example
  • No sideways scrolling on a 320px screen, also with a wide font, on every example
  • Every approved colour pair meets its contrast minimum, for every institution theme
  • No inline scripts or styles, so it runs under a strict Content Security Policy
  • Behaviour test: “timeout warning: opens before the end, Stay signed in extends the session, and time running out signs people out”

By people, with assistive technology

Automated tests find only some of the barriers people meet. These checks are still to be done.

Manual accessibility checks for timeout warning
CheckResultNotes
Keyboard onlyNot tested yetWaiting for the external audit with disabled people (decision D-09).
NVDA screen reader with Firefox or Chrome (Windows)Not tested yetWaiting for the external audit with disabled people (decision D-09).
JAWS screen reader with Chrome (Windows)Not tested yetWaiting for the external audit with disabled people (decision D-09).
VoiceOver screen reader with Safari (iPhone)Not tested yetWaiting for the external audit with disabled people (decision D-09).
TalkBack screen reader with Chrome (Android)Not tested yetWaiting for the external audit with disabled people (decision D-09).
Zoom to 400%, and increased text spacingNot tested yetWaiting for the external audit with disabled people (decision D-09).
Windows contrast themes (forced colours)Not tested yetWaiting for the external audit with disabled people (decision D-09).
Voice control (Voice Access or Dragon)Not tested yetWaiting for the external audit with disabled people (decision D-09).

Changes

Changes to timeout warning, newest first
VersionChange
0.4.0New components for services that take people from start to payment, in HTML, React, Astro and Django, each checked element by element against its documentation example and with axe on phones and computers. All are alpha.
0.1.0Added.

Every change, in What’s new

  • Dialog

    A box over the page that asks people to confirm something before it happens, such as deleting a draft.

  • Password input

    A password field with a Show button, so people can check what they typed before they send it.

Back to top

Something wrong, unclear or missing? Report a problem with this page or suggest a change to it on GitHub. You need a GitHub account.