When to use it#
- Use it on pages where reading could put someone at risk if another person saw the screen: how to get help after domestic violence, how to report abuse, some health pages. Put it on every page of that service, near the top.
- What it does not do: it doesn’t clear the browser history, the browser’s saved copies of pages or other open tabs. The visit can still be found in the history, and pages the person opened earlier in the same tab are still behind the Back button. Say so in your own text, and never promise that a visit leaves no trace.
- Choose a neutral site that says nothing about what the person was reading, such as a weather service. The address must be an
https://orhttp://address. A path on your own site works too. If people sign in, point the link at an endpoint of your own that ends the session: see End the session too. - If the script hasn’t loaded, the link works as an ordinary link and Back returns to the page. If someone opens it in a new tab from the context menu (the menu on a right-click), the first tab keeps the page open. A web page can’t prevent that.
- Not for ordinary links to other sites: use a Link.
Example#
Press the link, or press Tab and then Enter. In the examples on this page, navigate only shows where the visitor would go, so nothing leaves this site. useDemoLeave is a helper for this page: on your site, leave navigate out and the page is replaced. The Shift shortcut starts off here, so this page stays quiet for people who use a screen reader. Tick the box to turn it on. The sentence from QuickExit.Hint then appears next to the link, so people who see the page learn about the shortcut.
Off to start with, so this page stays quiet for people who use a screen reader. When it is on, press Shift three times, anywhere on the page.
import { Checkbox, Field, QuickExit } from '@kvirn-ui/react'
import { useState } from 'react'
import { useDemoLeave } from './demo-leave.tsx'
import { useQuickExitTexts } from './texts.ts'
export function DefaultQuickExit() {
const { texts } = useQuickExitTexts()
const { navigate, report } = useDemoLeave()
// The demo only: the shortcut starts off so this page stays quiet for screen reader users.
const [shortcut, setShortcut] = useState(false)
return (
<div>
<QuickExit.Root navigate={navigate} shortcut={shortcut}>
<QuickExit.Link href={texts.destination} />
<QuickExit.Hint />
</QuickExit.Root>
<Field.Root>
<Checkbox checked={shortcut} onCheckedChange={setShortcut} />
<Field.Label>{texts.tryShortcut}</Field.Label>
<Field.HelpText>{texts.tryShortcutHelp}</Field.HelpText>
</Field.Root>
{report}
</div>
)
}Use cases#
The cases below turn the Shift shortcut off with shortcut={false}, so that only the first example on this page listens for Shift. On your site, leave it on unless you have a reason, such as the case for screen reader users, and keep QuickExit.Hint after the link. It renders nothing while the shortcut is off.
A page that explains how to get help after domestic violence
Someone reads about support while another person may be nearby. Put the row first in the page, after the skip link and before the header, so the link is the second stop when you press Tab. Make the row a direct child of <body>, and don’t hide the link in a menu or only in the footer: it must be one press away from anywhere.
Press Tab. The first stop is the skip link, the second is the exit link.
Skip to the contentHeader of the municipality’s support service
Help if someone close to you hurts or frightens you
This page explains who can help you and how to make a report.
import { QuickExit, SkipLink } from '@kvirn-ui/react'
import { useDemoLeave } from './demo-leave.tsx'
import { useQuickExitTexts } from './texts.ts'
export function SupportPage() {
const { texts } = useQuickExitTexts()
const { navigate, report } = useDemoLeave()
return (
<div>
<p>
<small>{texts.tabOrder}</small>
</p>
<SkipLink href="#quick-exit-support-main">{texts.skipLabel}</SkipLink>
<QuickExit.Root navigate={navigate} shortcut={false}>
<QuickExit.Link href={texts.destination} />
<QuickExit.Hint />
</QuickExit.Root>
<p>{texts.header}</p>
<div id="quick-exit-support-main">
<h4>{texts.supportHeading}</h4>
<p>{texts.supportText}</p>
</div>
{report}
</div>
)
}Props in this example:
Information: Did you know?
Set a Referrer-Policy: no-referrer header on these pages. The link asks for no referrer (the address of the page the person came from), but the browser follows that only when it follows the link itself, not when the component takes over for a click or three presses of Shift.
End the session too#
In a service where people sign in, leaving the page is not enough: the session would stay open in this browser. Point href at an endpoint on your own site that ends the session and then redirects to the neutral site.
Your endpoint must do four things:
- End the session on your server, and clear the session cookie by setting it with
Max-Age=0. The cookie’s name,PathandDomainmust match the ones you set it with. - Redirect to the neutral page, for example with the status
303. - Answer a plain
GETrequest, so the link works without JavaScript. - Keep personal data out of the address you redirect to. The browser saves that address in its history.
The endpoint is your code, not the library’s. This is a sketch in the form of a web standard request handler:
// GET /api/quick-exit, on your own site
export function GET() {
// Also end the session on your side here, for example in your session store.
const headers = new Headers({ Location: 'https://www.smhi.se' })
headers.append('Set-Cookie', 'session=; Max-Age=0; Path=/; Secure; HttpOnly; SameSite=Lax')
return new Response(null, { status: 303, headers })
}The link leaves in the same tab: a click, a click with Ctrl held and a middle click all replace this page, and so does Shift three times when the shortcut is on. The example below has the shortcut off and uses href with a path on this site. As in every example on this page, navigate only reports where the visitor would go.
Signed in as Alex Berg
Your report
Your report is saved as a draft. You can finish it later.
import { QuickExit } from '@kvirn-ui/react'
import { useDemoLeave } from './demo-leave.tsx'
import { useQuickExitTexts } from './texts.ts'
export function EndSession() {
const { texts } = useQuickExitTexts()
const { navigate, report } = useDemoLeave()
return (
<div>
<QuickExit.Root navigate={navigate} shortcut={false}>
{/* Your own endpoint: it ends the session, then sends the visitor on. */}
<QuickExit.Link href={texts.endpoint} />
<QuickExit.Hint />
</QuickExit.Root>
<p>{texts.signedIn}</p>
<h4>{texts.reportHeading}</h4>
<p>{texts.reportText}</p>
{report}
</div>
)
}Make the exit fast#
QuickExit hides the page at once. Then the browser has to load the destination. The steps below make that load quick, safest first. Put the tags in the <head> of your page template (your layout) on every page that has the link, and set headers on your server. QuickExit itself adds nothing and sends nothing: it never contacts another site before someone leaves.
1. Choose a light destination
This costs nothing and tells nobody anything. Pick a destination that is:
- on your own origin (the same site address as the page), as one static page;
- reached with no redirect chain. If the exit goes through your session-ending endpoint, keep it to one redirect;
- free of heavy scripts, images and fonts;
- cached: for example
Cache-Control: public, max-age=86400on the neutral page; - served over HTTP/2 or newer, which sends several requests over one connection.
2. A neutral page on your own origin, loaded ahead of time
You ask the browser to fetch the neutral page while the person reads. No other site is contacted, and the request shows only in your own logs. Two hints do this. Both are hints: a browser may ignore them.
<link rel="prefetch" href="/neutral" /><script type="speculationrules">
{ "prefetch": [{ "urls": ["/neutral"] }] }
</script>Browsers differ in what they support: Chromium-based browsers such as Chrome and Edge support speculation rules. A browser that doesn’t know them ignores the script, and the exit still works, only without the head start. A "prerender" rule has the same shape, but it also runs the page’s JavaScript in the background, so use it only for a plain static page.
The most dependable choice is a service worker that stores the neutral page itself, because the two hints above may be ignored. It also works offline. It needs HTTPS (localhost counts while you build).
// sw.js, served from your own origin over HTTPS
self.addEventListener('install', (event) => {
event.waitUntil(caches.open('neutral-v1').then((cache) => cache.add('/neutral')))
})
self.addEventListener('fetch', (event) => {
if (new URL(event.request.url).pathname === '/neutral') {
event.respondWith(caches.match('/neutral').then((hit) => hit ?? fetch(event.request)))
}
})navigator.serviceWorker.register('/sw.js')3. A destination on another site: connect ahead
preconnect asks the browser to open the connection to that site early, and dns-prefetch does only the first step, finding the site’s address. Put them in your page head, so they run when the page loads.
<link rel="preconnect" href="https://www.smhi.se" />
<link rel="dns-prefetch" href="https://www.smhi.se" />This contacts that site. It happens from the moment someone opens the page, shows in network logs, and tells that site and the network that visitors of this page exist. The library never does it for you. If that is not acceptable, choose one of the two steps above.
4. Test it
Slow the network down in your browser’s developer tools, press the link and check two things: the tab goes blank at once, and the destination follows. Test in a browser without speculation rules too, such as Firefox: the exit must still work.
A health page for people who use a screen reader
NVDA, a screen reader for Windows, uses the Shift key to pause speech. Three presses of Shift, each less than five seconds after the last, would then leave the page. In browse mode (how a screen reader moves through a page), NVDA and JAWS may also pass on a lone Shift when someone jumps back through headings. If many of your readers use a screen reader, turn the shortcut off. The link stays, and keyboard and pointer users still reach it.
import { QuickExit } from '@kvirn-ui/react'
import { useDemoLeave } from './demo-leave.tsx'
import { useQuickExitTexts } from './texts.ts'
export function NoShortcut() {
const { texts } = useQuickExitTexts()
const { navigate, report } = useDemoLeave()
return (
<div>
<QuickExit.Root navigate={navigate} shortcut={false}>
<QuickExit.Link href={texts.destination} />
</QuickExit.Root>
<h4>{texts.healthHeading}</h4>
<p>{texts.healthText}</p>
{report}
</div>
)
}Props in this example:
shortcuton QuickExit.Root
Your own row and link
Your site already has its own markup for the row and the link. Spread the props from the hook on them and use the label and the hint from the hook. Give the link aria-describedby with the id of the hint, and show the hint only while the shortcut is on. The hook gives the same key listener, announcement and exit as the parts.
This link is your own <a> element, with the behaviour from the hook.
import { Checkbox, Field, useQuickExit } from '@kvirn-ui/react'
import { useId, useState } from 'react'
import { useDemoLeave } from './demo-leave.tsx'
import { useQuickExitTexts } from './texts.ts'
export function OwnMarkup() {
const { texts } = useQuickExitTexts()
const { navigate, report } = useDemoLeave()
const hintId = useId()
// The demo only: the shortcut starts off so this page stays quiet for screen reader users.
const [shortcut, setShortcut] = useState(false)
const quickExit = useQuickExit({ href: texts.destination, navigate, shortcut })
return (
<div>
<div {...quickExit.rootProps}>
<a {...quickExit.linkProps} aria-describedby={shortcut ? hintId : undefined}>
{quickExit.label}
</a>
{shortcut ? (
<p {...quickExit.hintProps} id={hintId}>
{quickExit.hint}
</p>
) : null}
</div>
<Field.Root>
<Checkbox checked={shortcut} onCheckedChange={setShortcut} />
<Field.Label>{texts.tryShortcut}</Field.Label>
</Field.Root>
<p>
<small>{texts.ownMarkup}</small>
</p>
{report}
</div>
)
}Props in this example:
Information: Did you know?
Spread linkProps on a real <a>. It keeps its address, so it still works as an ordinary link until the script has loaded.
Accessibility#
What it does for you#
- APG pattern: none. QuickExit is a native link that navigates.
- Deviations: a document-level Shift ×3 shortcut, on by default.
shortcut={false}removes it. It also works in text fields: a Shift counts only when pressed alone. - Native elements used:
<div>(Root),<a href>(Link).
| Part | Element / role | ARIA | Notes |
|---|---|---|---|
| Root | <div> | none | class="kv-quick-exit", data-state="idle", "armed" after one or two Shifts, "leaving" once the page is hidden |
| Hint | <p> | none | class="kv-quick-exit-hint", the sentence quickExit.hint ("Or press Shift 3 times."), or your children. The link's aria-describedby points at it, only while a Hint is mounted. Renders nothing when shortcut={false}. No aria-keyshortcuts |
| Link | <a href> | none, no role override | class="kv-quick-exit-link", name quickExit.label, rel="noreferrer" and referrerpolicy="no-referrer", which apply only when the browser follows the link itself. No href unless it is an http(s) URL, absolute or relative |
What you need to do#
- Place
QuickExit.Hintinside Root after the Link while the shortcut is on: without it a development warning says sighted keyboard users are not told about the shortcut. - Put Root as a direct child of
<body>, early in the focus order (after the skip link), and pass a neutralhref. - Wrap the app in
KvirnProvider: the Shift count is announced through it. - NVDA uses Shift to pause speech, so the shortcut can fire by accident. The shortcut is on by default, so a person who pauses speech with Shift three times leaves the page. Set
shortcut={false}to opt out. navigatemust replace the history entry with a full navigation (the defaultlocation.replacedoes). A router push keeps the entry and leaves a blank page.- While a modal dialog is open the page is inert, so the link cannot be reached: only the shortcut works.
- A web page cannot clear history, cache or other tabs: say that in your own copy. Earlier history entries remain.
- The anchor's
relandreferrerpolicyapply when the browser follows the link itself. A click and Shift ×3 go throughlocation.replace, which uses the page's own policy: set aReferrer-Policy: no-referrerheader if the destination must not learn where the visitor came from.
Warning: Don't forget
Wrap your app in a KvirnProvider. Without it the count of Shift presses is not announced, so a screen reader user gets no feedback while pressing Shift (4.1.3 Status Messages, level AA). The exit itself still works.
Visual and modes#
- A hint you override with a longer sentence (more than 3 lines on a narrow screen, or 2 lines on a wide one) makes the row taller than the scroll padding the theme sets for the sticky row, so a focused element can end up under it (2.4.11).
Headless: no CSS. With @kvirn-ui/theme/theme.css the row is kv-quick-exit and the link kv-quick-exit-link.
- Target size: the link is larger than 24 by 24 CSS pixels (2.5.8 Target Size (Minimum), AA).
- Contrast: the link text and the focus ring meet 4.5:1 and 3:1 against their background (1.4.3 Contrast (Minimum), AA; 1.4.11 Non-text Contrast, AA).
- Forced colours: the forced-colours sweep checks that the boundary and the focus ring are drawn.
- Reflow: the row stacks on a narrow screen (1.4.10 Reflow, AA), and the reflow sweep checks every story at 320 CSS pixels for sideways scrolling.
- Print: the row is hidden when the page is printed.
Warning: Don't forget
Keep the hint to one short sentence. A long hint makes the row taller than the space the default theme leaves for it, and a focused element can end up hidden under the row (2.4.11 Focus Not Obscured (Minimum), level AA).
Focus management#
- Initial focus: not moved.
- Trap: no.
- Restore to: not applicable. The page is replaced.
- Never obscured by: the theme sticks the row only on tall screens and leaves room above the focused field for a short row (2.4.11 Focus Not Obscured (Minimum), AA).
WCAG success criteria#
- 2.1.1 Keyboard (A): the link and the shortcut work from the keyboard.
- 2.1.4 Character Key Shortcuts (A): not applicable. Shift is a modifier, not a character key;
shortcut={false}is offered anyway. - 2.4.7 Focus Visible (AA): the link shows a focus ring.
- 2.4.11 Focus Not Obscured (Minimum) (AA): the theme leaves room for the sticky row.
- 2.5.8 Target Size (Minimum) (AA): the link is larger than 24 by 24 CSS pixels.
- 3.2.5 Change on Request (AAA): navigation only on activation. Met, though AAA is not the target.
- 4.1.3 Status Messages (AA): the Shift count is announced politely.
Keyboard#
- Focus
- native
- Selection follows focus
- n/a
- Arrows wrap
- n/a
- Shortcuts
- Shift ×3, on by default,
shortcut={false}
The link is one Tab stop and no focus is moved: the page is replaced. A Shift counts when it is released, and only if no other key or pointer button was pressed while it was down. Escape and arrow keys are not handled.
| Key | Where | What happens |
|---|---|---|
| Tab | Before the link | Moves focus to the link Test: quick-exit.test.tsx › keyboard › Tab moves focus to the link and Shift+Tab leaves it |
| Shift+Tab | On the link | Moves focus to the previous stop. Announces nothing and is not counted Test: quick-exit.test.tsx › read aloud › Shift+Tab is silent and is not counted |
| Enter | Link | Hides the page, empties the title, replaces it with hrefTest: quick-exit.test.tsx › keyboard › Enter on the link hides the page, empties the title and navigates |
| Space | Link | No effect: it is a link Test: quick-exit.test.tsx › keyboard › Space does nothing |
| Shift ×3 | Anywhere on the page | Same as Enter, when shortcut is on. Each Shift counts on key up, within windowMs of the last (default 5 s)Test: quick-exit.test.tsx › keyboard › Shift three times leaves from anywhere on the page |
| Shift ×1 | Anywhere on the page | Announces "Press Shift 2 more times…" (polite) and arms Test: quick-exit.test.tsx › read aloud › Shift once says two more presses |
| Shift ×2 | Anywhere on the page | Announces "Press Shift 1 more time…" (polite) Test: quick-exit.test.tsx › read aloud › Shift twice says one more press |
| Any other key | Armed | Resets the count, silently Test: quick-exit.test.tsx › keyboard › another key between the Shifts resets the count |
| Any pause over windowMs | Armed | Resets the count, silently Test: quick-exit.test.tsx › keyboard › presses further apart than the window do not add up |
| Shift held (repeat) | Anywhere on the page | Not counted Test: quick-exit.test.tsx › keyboard › a held Shift (repeat) is not counted |
| Shift + a letter, or Shift + click | Anywhere on the page | Not counted: only a Shift pressed alone counts. Test: quick-exit.test.tsx › keyboard › Shift three times works in a text field, and typing capitals does not count, quick-exit.test.tsx › keyboard › Shift+click is not counted |
| Alt / Control / Meta + Shift | Anywhere on the page | Not counted, and resets the count Test: quick-exit.test.tsx › keyboard › Alt, Control or Meta with Shift is not counted |
| Shift ×3 | A text field | Leaves, like anywhere else Test: quick-exit.test.tsx › keyboard › Shift three times works in a text field, and typing capitals does not count |
| Shift ×3 | shortcut={false} | No listener: nothing is counted or announced Test: quick-exit.test.tsx › keyboard › shortcut={false} ignores Shift three times and announces nothing |
Information: Did you know?
Three presses of Shift leave the page, as long as no more than five seconds pass between two presses. Any other key in between starts the count again. A Shift counts when it is released, and only if nothing else was pressed while it was down, so Shift+Tab or a capital letter in a form is not a press.
Announcements#
QuickExit tells screen reader users about these changes without moving focus. Each message waits until the screen reader is quiet (polite) or interrupts it (assertive).
| When | What it says | Message key | Politeness |
|---|---|---|---|
| Shift press 1 and 2 | quickExit.shortcutRemaining | Polite |
Change the text#
For your whole app, pass messages to KvirnProvider. For one QuickExit, pass its messages prop.
<KvirnProvider messages={{ quickExit: { shortcutRemaining: '…' } }}>Warning: Don't forget
Announcements need a KvirnProvider around your app, outside any <form>, or an Announcer of your own. Without one nothing is announced, and a development warning says so.
What a screen reader reads#
| State or action | Read aloud | Politeness | Test |
|---|---|---|---|
| Idle | link, Leave this page, Or press Shift 3 times. | none | quick-exit.test.tsx › read aloud › idle reads the link by its name and the hint |
| Shift ×1 | Press Shift 2 more times to leave this page | polite | quick-exit.test.tsx › read aloud › Shift once says two more presses |
| Shift ×2 | Press Shift 1 more time to leave this page | polite | quick-exit.test.tsx › read aloud › Shift twice says one more press |
Idle, shortcut={false} | link, Leave this page, no description | none | quick-exit.test.tsx › hint › there is no hint and no description when shortcut={false} |
| Shift+Tab | nothing | none | quick-exit.test.tsx › read aloud › Shift+Tab is silent and is not counted |
API reference#
import { QuickExit, useQuickExit } from '@kvirn-ui/react'QuickExit.Root
Renders <div>, the row that holds the link. It takes every attribute of a <div> and passes ref to it. It owns the key listener and the announcement, and sets data-state. Put it as a direct child of <body>, and mount one with the shortcut on per page. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
shortcut | boolean | true | Pressing Shift three times, from anywhere on the page, leaves it, also in a text field. A Shift counts when it is released, and only if nothing else was pressed while it was down, so Shift+Tab, a capital letter or Shift+click is not a press. false adds no key listener at all, so nothing is counted or announced, QuickExit.Hint renders nothing and the link is the only way. Mount only one QuickExit with the shortcut on per page: a second one warns in development. |
navigate | (href: string) => void | window.location.replace(href) | How the page is left. It gets the full address, and the page is already hidden. Use it only for a full navigation that replaces the history entry, or for a function that just reports, as the examples on this page do. A router push keeps the entry and leaves a blank page. |
windowMs | number | 5000 | The longest gap between two Shift presses, in milliseconds. A longer gap starts the count again. |
messages | Partial<KvirnMessages['quickExit']> | – | Overrides the texts for this instance: { label, hint, shortcutRemaining }. The provider’s language is the default. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-quick-exit | always | The part class. The default theme draws the row: sticky at the top when the window is tall enough, static when it is short. |
data-state | "idle", "armed" or "leaving" | armed: one or two Shift presses are counted. leaving: the page is hidden and navigate has been called. |
QuickExit.Link
Renders <a href> with the role link. It takes every attribute of an <a> and passes ref to it. It must be inside QuickExit.Root. While a modal dialog is open, the rest of the page is inert (it can’t be focused or clicked), so the link can’t be reached and only the shortcut works. In a signed-in service, point href at an endpoint that ends the session: End the session too.
| Prop | Type | Default | Description |
|---|---|---|---|
href | string | Required | Where the person goes: an https:// or http:// address, or a path on your own site such as /api/quick-exit. Anything else renders the link without an address, warns once in development and goes nowhere. |
children | ReactNode | the message quickExit.label | Your own label. It replaces the message, so write it in the provider’s language. Keep the visible text and the name the same. |
as | ElementType | 'a' | Changes the element to a component of your own, only where you need a router link. It must render an <a href> and forward its ref, and it gets the other props, the ref and the part’s class. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-quick-exit-link | always | The part class. The default theme gives the link its own filled look. |
aria-describedby | the id of the Hint | Set on the link only while a QuickExit.Hint is mounted, so a screen reader reads the hint after the name. |
rel | "noreferrer" | Asks the browser to send no referrer (the address of the page the person came from) when it follows the link itself, for example with JavaScript off. |
referrerpolicy | "no-referrer" | The same request, as a policy on the link. Both only apply when the browser follows the link itself. |
QuickExit.Hint
Renders <p> with the sentence “Or press Shift 3 times.” Put it inside QuickExit.Root after the link, so sighted keyboard users learn about the shortcut and the link is described by it. It renders nothing when the Root has shortcut={false}. With the shortcut on and no Hint, a warning appears once in development. It must be inside QuickExit.Root.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | the message quickExit.hint | Your own sentence. Keep it short: more than 3 lines below 40rem, or 2 lines at 40rem and wider, makes the row taller than the scroll padding the theme sets for the sticky row, so a focused element can end up under it (2.4.11). |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-quick-exit-hint | always | The part class. The default theme draws the sentence next to the link. |
useQuickExit
Gives the behaviour to your own <div> and <a href>: the key listener, the announcement and the exit.
Options
| Prop | Type | Default | Description |
|---|---|---|---|
href | string | undefined | Required | Where the person goes: an https:// or http:// address, or a path on your own site. Anything else warns in development and goes nowhere. |
shortcut | boolean | true | Pressing Shift three times, from anywhere on the page, leaves it, also in a text field. A Shift counts when it is released, and only if nothing else was pressed while it was down, so Shift+Tab, a capital letter or Shift+click is not a press. false adds no key listener at all, so nothing is counted or announced, QuickExit.Hint renders nothing and the link is the only way. Mount only one QuickExit with the shortcut on per page: a second one warns in development. |
navigate | (href: string) => void | window.location.replace(href) | How the page is left. It gets the full address, and the page is already hidden. Use it only for a full navigation that replaces the history entry, or for a function that just reports, as the examples on this page do. A router push keeps the entry and leaves a blank page. |
windowMs | number | 5000 | The longest gap between two Shift presses, in milliseconds. A longer gap starts the count again. |
messages | Partial<KvirnMessages['quickExit']> | – | Overrides the texts for this instance: { label, hint, shortcutRemaining }. The provider’s language is the default. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
rootProps | QuickExitRootPartProps | – | Spread on the row element: the class and data-state. |
linkProps | QuickExitLinkPartProps | – | Spread on an <a>: the class, href, rel, referrerpolicy and the click handlers that leave the page. |
hintProps | QuickExitHintPartProps | – | Spread on a <p>: the class. Also give the link aria-describedby with the id of this <p>. |
hint | string | – | The message quickExit.hint: the sentence to show next to the link while the shortcut is on. |
label | string | – | The message quickExit.label: the default text of the link. |
state | 'idle' | 'armed' | 'leaving' | – | The same value as data-state, for your own markup. |
Strings
These are the default texts in @kvirn-ui/i18n.
For your whole app, pass messages to KvirnProvider. For one QuickExit, pass its messages prop.
Have a native speaker review the Finnish texts and both sets of Norwegian texts before you launch.
quickExit.label
The link’s visible text and its name, when you give no children. It says what the link does.
| Language | Default text |
|---|---|
| Svenska | Lämna sidan |
| Suomi | Poistu sivulta |
| Norsk bokmål | Forlat siden |
| Norsk nynorsk | Forlat sida |
| English | Leave this page |
quickExit.hint
The sentence QuickExit.Hint shows next to the link while the shortcut is on. It names the shortcut.
| Language | Default text |
|---|---|
| Svenska | Eller tryck på Skift 3 gånger. |
| Suomi | Tai paina vaihtonäppäintä 3 kertaa. |
| Norsk bokmål | Eller trykk Skift 3 ganger. |
| Norsk nynorsk | Eller trykk Skift 3 gonger. |
| English | Or press Shift 3 times. |
quickExit.shortcutRemaining
Announced politely after the first and the second Shift press: how many more presses leave the page.
| Language | Default text |
|---|---|
| Svenska | Tryck på Skift 2 gånger till för att lämna sidan |
| Suomi | Paina vaihtonäppäintä vielä 2 kertaa poistuaksesi sivulta |
| Norsk bokmål | Trykk Skift 2 ganger til for å forlate siden |
| Norsk nynorsk | Trykk Skift 2 gonger til for å forlate sida |
| English | Press Shift 2 more times to leave this page |
Known issues#
- Keyboard tests run in Chromium only. The keyboard rows run in Vitest browser mode on Chromium, not in WebKit. Test in Safari with your own assistive technology.
- NVDA pauses speech with Shift, so the shortcut can fire by accident.
shortcut={false}opts out. - Browse-mode quick navigation: in NVDA and JAWS, backwards quick navigation (Shift+H, Shift+K, Shift+1 to 6) may reach the page as a lone Shift and count, so three backwards heading jumps could leave the page. Check it with NVDA and JAWS in your service.
- Your own strings: if you override the strings, have a native speaker check them.
Information: Did you know?
What if the destination is slow? The page is hidden before the navigation starts, so a slow destination shows a blank tab, never the sensitive page. The fastest and most private choices are a destination on your own origin, or your own endpoint that ends the session and redirects. QuickExit does not preload or preconnect, because that would contact another site from a sensitive page: see Make the exit fast for what you can add yourself, and what each choice tells others.
Testing#
The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.
| AT + browser + OS | Agent check | Human check | Result | Notes |
|---|---|---|---|---|
| Automated (re-runnable tests) | ||||
| axe, WCAG 2.2 A and AA, every story, 4 themes | pass | n/a | pass | quick-exit.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | quick-exit.test.tsx › idle reads the link by its name and the hint; expectNoA11yViolations |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | 14 rows, each names a test (quick-exit.test.tsx › keyboard › Tab moves focus to the link and Shift+Tab leaves it) |
| Focus order and management | pass | n/a | pass | quick-exit.test.tsx asserts focus (toHaveFocus); first rule: keyboard › Tab moves focus to the link and Shift+Tab leaves it |
| Display modes (forced colours, 320px reflow, text spacing, reduced motion) | pass | n/a | pass | the four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI |
| Core (required for beta) | ||||
| NVDA + Chrome + Windows | pending | pending | pending | |
| VoiceOver + Safari + iOS | pending | pending | pending | |
| NVDA / JAWS browse mode, Shift+H ×3 | pending | pending | pending | see Known issues: browse-mode quick navigation |
| Release (before 1.0 and each minor) | ||||
| JAWS + Chrome + Windows | pending | pending | pending | |
| TalkBack + Chrome + Android | pending | pending | pending | |
| VoiceOver + Safari + macOS | pending | pending | pending |
What to check#
- Tab to "Leave this page" and press Enter: the page goes blank at once and the destination loads.
- With the shortcut on, press Shift once, then twice: "Press Shift 2 more times…" and then "Press Shift 1 more time…" are announced. Press Shift a third time: the page is left.
- A capital letter and Shift+Tab in a form field do not count as presses.
- In NVDA browse mode, press Shift+H three times to jump back through headings: the page stays open.
- With a modal dialog open, the Shift shortcut still works while the link can't be reached.
Warning: Don't forget
The component is checked with automated accessibility tests and keyboard tests. Test it, and the label “Leave this page”, with your own users and their assistive technology before you rely on it in a service that protects people.