Skip to main content
Primitives

Details

A native details element that shows and hides content without JavaScript, with its open state in React.

Used by govuk-react's service navigation.

In govuk-react

govuk-react's service navigation, built with this primitive, at mobile width.

A menu that works without JavaScript, through a native `details`.

Code
<ServiceNavigation.DetailsComposite serviceName="Service name" serviceHref="#">
  <ServiceNavigation.ItemComposite href="#">Navigation item 1</ServiceNavigation.ItemComposite>
  <ServiceNavigation.ItemComposite href="#" current>
    Navigation item 2
  </ServiceNavigation.ItemComposite>
  <ServiceNavigation.ItemComposite href="#">Navigation item 3</ServiceNavigation.ItemComposite>
</ServiceNavigation.DetailsComposite>

Usage

import { Details } from '@govuk-react/primitives/details';

<Details onOpenChange={(open) => console.log(open)}>
  <summary>Menu</summary>
  <ul>…</ul>
</Details>;

A native details, for content that shows and hides without JavaScript. It has no custom element, because the browser holds its state before React hydrates. open and onOpenChange control it once hydrated. A user’s change before hydration is reported through onOpenChange rather than undone. See Disclosure for why it may not suit a menu.

API reference

Details.Details

A native <details>, which shows and hides its content without JavaScript.

PropType
open

Whether it's open, to control it once hydrated.

boolean
onOpenChange

Called when the user opens or closes it.

(open: boolean, details: ChangeDetails) => void

Types

TypeDefinition
ChangeDetails

What a change handler is told about a change, as its second argument.

{ beforeHydration: boolean }