Skip to main content
Primitives

Exit this page

Lets users leave the page quickly.

Used by govuk-react's exit this page.

Unstyled

The primitive on plain elements, with no GOV.UK markup or styles: what you start from in your own library.

Code
<ExitThisPage.Root hideContentClass="hide-content" overlayClass="overlay">
  <ExitThisPage.Trigger href="https://www.bbc.co.uk/weather">
    Exit this page
    <ExitThisPage.Indicator />
  </ExitThisPage.Trigger>
  <ExitThisPage.Status className="visually-hidden" />
</ExitThisPage.Root>

In govuk-react

govuk-react's exit this page, built with this primitive.

Code
<ExitThisPage.Composite />

Usage

import * as ExitThisPage from '@govuk-react/primitives/exit-this-page';

<ExitThisPage.SkipLink href="https://www.bbc.co.uk/weather">Exit this page</ExitThisPage.SkipLink>;

<ExitThisPage.Root hideContentClass="hide-content" overlayClass="overlay">
  <ExitThisPage.Trigger href="https://www.bbc.co.uk/weather">
    Exit this page
    <ExitThisPage.Indicator />
  </ExitThisPage.Trigger>
  <ExitThisPage.Status className="visually-hidden" />
</ExitThisPage.Root>;

Lets users leave the page quickly. Without JavaScript the button is a plain link. Once upgraded, the button, a SkipLink, or pressing Shift 3 times within 5 seconds hides the page behind an overlay that says it’s loading, and goes to the button’s href. Indicator shows the presses, and Status tells screen readers how many more are needed. Only the page’s first Root listens for Shift and skip links. Before leaving, the element fires a cancelable govuk-react-exit-this-page:exit event, so a test can stay on the page.

Inline script

To make the markup interactive before React hydrates, inline @govuk-react/primitives/inline/exit-this-page-element.js, or render it from React on the server:

import { InlineScript, exitThisPage } from '@govuk-react/primitives/inline-script';

<InlineScript script={exitThisPage} nonce={nonce} />;

How inline scripts work

API reference

ExitThisPage.Root

PropType
activatedAnnouncement

Announced once activated. Defaults to "Loading.".

string
timedOutAnnouncement

Announced when the Shift presses time out. Defaults to "Exit this page expired.".

string
pressTwoMoreTimesAnnouncement

Announced after one press of Shift. Defaults to "Shift, press 2 more times to exit.".

string
pressOneMoreTimeAnnouncement

Announced after two presses of Shift. Defaults to "Shift, press 1 more time to exit.".

string
indicatorVisibleClass

Classes for the indicator while counting presses.

string
lightOnClass

Classes for each light of the indicator once pressed.

string
hideContentClass

Classes for body that hide the page behind the overlay.

string
overlayClass

Classes for the overlay. Without them, inline styles cover the page.

string

ExitThisPage.Indicator

Shows how many times Shift has been pressed. Has three Lights unless given children.

PropType
asChild

Render the only child instead, with this part's props merged onto it.

boolean

ExitThisPage.Light

One press of Shift.

PropType
asChild

Render the only child instead, with this part's props merged onto it.

boolean

A link anywhere on the page, such as in the skip links, that exits too.

PropType
asChild

Render the only child instead, with this part's props merged onto it.

boolean

ExitThisPage.Status

Tells screen readers how many more presses are needed. Make it visually hidden.

PropType
asChild

Render the only child instead, with this part's props merged onto it.

boolean

ExitThisPage.Trigger

The link to a safe page, which the element follows once it has hidden the page.

PropType
asChild

Render the only child instead, with this part's props merged onto it.

boolean