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} />;API reference
ExitThisPage.Root
| Prop | Type |
|---|---|
activatedAnnouncementAnnounced once activated. Defaults to "Loading.". | string |
timedOutAnnouncementAnnounced when the Shift presses time out. Defaults to "Exit this page expired.". | string |
pressTwoMoreTimesAnnouncementAnnounced after one press of Shift. Defaults to "Shift, press 2 more times to exit.". | string |
pressOneMoreTimeAnnouncementAnnounced after two presses of Shift. Defaults to "Shift, press 1 more time to exit.". | string |
indicatorVisibleClassClasses for the indicator while counting presses. | string |
lightOnClassClasses for each light of the indicator once pressed. | string |
hideContentClassClasses for | string |
overlayClassClasses 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.
| Prop | Type |
|---|---|
asChildRender the only child instead, with this part's props merged onto it. | boolean |
ExitThisPage.Light
One press of Shift.
| Prop | Type |
|---|---|
asChildRender the only child instead, with this part's props merged onto it. | boolean |
ExitThisPage.SkipLink
A link anywhere on the page, such as in the skip links, that exits too.
| Prop | Type |
|---|---|
asChildRender 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.
| Prop | Type |
|---|---|
asChildRender 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.
| Prop | Type |
|---|---|
asChildRender the only child instead, with this part's props merged onto it. | boolean |