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-oneanddata-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-timeoutto the server, or people will be signed out before the warning.
Example: The warning, as it appears
<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><>
<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.cssincludes it. To load only the parts you use:core.css, thencomponents/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:
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:
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 %}):
{% load ggds %}
{% ggds_timeout_warning timeout=1200 keep_alive="/session/keep-alive/" sign_out="/signed-out/" %}Classes and states
| Class | What it does |
|---|---|
.ggds-timeout-warning | On the dialog: the timeout warning. data-ggds-timeout, -warn, -keep-alive and -sign-out configure it. |
.ggds-timeout-warning__time | The 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.
| Check | Result | Notes |
|---|---|---|
| Keyboard only | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
| NVDA screen reader with Firefox or Chrome (Windows) | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
| JAWS screen reader with Chrome (Windows) | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
| VoiceOver screen reader with Safari (iPhone) | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
| TalkBack screen reader with Chrome (Android) | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
| Zoom to 400%, and increased text spacing | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
| Windows contrast themes (forced colours) | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
| Voice control (Voice Access or Dragon) | Not tested yet | Waiting for the external audit with disabled people (decision D-09). |
Changes
| Version | Change |
|---|---|
| 0.4.0 | New 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.0 | Added. |
Related components
Something wrong, unclear or missing? or suggest a change to it on GitHub. You need a GitHub account.