Disclosure
A button that shows and hides some content, such as a navigation menu on small screens.
Used by govuk-react's service navigation.
Unstyled
The primitive on plain elements, with no GOV.UK markup or styles: what you start from in your own library.
Code
<nav aria-label="Menu">
<Disclosure.Root>
<Disclosure.Trigger aria-controls="navigation">Menu</Disclosure.Trigger>
<Disclosure.Content asChild>
<ul id="navigation">
<li>
<a href="#home">Home</a>
</li>
<li>
<a href="#account">Your account</a>
</li>
<li>
<a href="#sign-out">Sign out</a>
</li>
</ul>
</Disclosure.Content>
</Disclosure.Root>
</nav>In govuk-react
govuk-react's service navigation, built with this primitive.
Code
<ServiceNavigation.Composite>
<ServiceNavigation.ItemComposite href="#">Navigation item 1</ServiceNavigation.ItemComposite>
<ServiceNavigation.ItemComposite href="#" active>
Navigation item 2
</ServiceNavigation.ItemComposite>
<ServiceNavigation.ItemComposite href="#">Navigation item 3</ServiceNavigation.ItemComposite>
</ServiceNavigation.Composite>Usage
import * as Disclosure from '@govuk-react/primitives/disclosure';
<nav aria-label="Menu">
<Disclosure.Root media="(min-width: 40.0625em)">
<Disclosure.Trigger>Menu</Disclosure.Trigger>
<Disclosure.Content asChild>
<ul id="navigation">…</ul>
</Disclosure.Content>
</Disclosure.Root>
</nav>;
A button that shows and hides some content, such as a navigation menu on small screens. Without JavaScript the content is shown and the button hidden. While media matches, the content is always shown and the button hidden.
open and onOpenChange control it once hydrated, such as to close a menu after navigating. A user’s click before hydration is reported through onOpenChange rather than undone. defaultOpen starts it open.
Inline script
To make the markup interactive before React hydrates, inline @govuk-react/primitives/inline/disclosure-element.js, or render it from React on the server:
import { InlineScript, disclosure } from '@govuk-react/primitives/inline-script';
<InlineScript script={disclosure} nonce={nonce} />;API reference
Disclosure.Root
| Prop | Type |
|---|---|
mediaWhile this media query matches, the content is always shown and the button hidden. | string |
openWhether the content is shown, to control it once hydrated. | boolean |
defaultOpenWhether the content starts shown once the element upgrades. | boolean |
onOpenChangeCalled when the user shows or hides the content. | (open: boolean, details: ChangeDetails) => void |
Disclosure.Content
The content the button shows and hides. Give it an id for the button's aria-controls.
| Prop | Type |
|---|---|
asChildRender the only child instead, with this part's props merged onto it. | boolean |
Disclosure.Trigger
The show and hide button. Hidden until the element upgrades.
| Prop | Type |
|---|---|
asChildRender the only child instead, with this part's props merged onto it. | boolean |