Disclosure
Reveal supporting content with a native disclosure, laid out as a Material 3 list item with a round state layer behind the chevron.
Default
Supporting details
Keep supporting information close to its trigger.
Show code
---
import Disclosure from '@dhekode/ui/primitives/Disclosure.tsx';
---
<Disclosure summary="Supporting details"><p>Keep supporting information close to its trigger.</p></Disclosure>Initially open
Visible on arrival
This starts expanded and can still be closed.
Show code
---
import Disclosure from '@dhekode/ui/primitives/Disclosure.tsx';
---
<Disclosure summary="Visible on arrival" open><p>This starts expanded and can still be closed.</p></Disclosure>Numbered
First detail
Numbering is decorative.
Show code
---
import Disclosure from '@dhekode/ui/primitives/Disclosure.tsx';
---
<Disclosure summary="First detail" index={1}><p>Numbering is decorative.</p></Disclosure>Large
Section-scale detail
The larger treatment suits section content.
Show code
---
import Disclosure from '@dhekode/ui/primitives/Disclosure.tsx';
---
<Disclosure summary="Section-scale detail" size="lg"><p>The larger treatment suits section content.</p></Disclosure>Independent items
Design notes
Each item opens independently.
Implementation notes
Both can stay open.
Show code
---
import Disclosure from '@dhekode/ui/primitives/Disclosure.tsx';
---
<Disclosure summary="Design notes"><p>Each item opens independently.</p></Disclosure>
<Disclosure summary="Implementation notes"><p>Both can stay open.</p></Disclosure>Exclusive group
First option
One item at a time.
Second option
Opening this closes its sibling.
Show code
---
import Disclosure from '@dhekode/ui/primitives/Disclosure.tsx';
---
<Disclosure summary="First option" name="demo-exclusive"><p>One item at a time.</p></Disclosure>
<Disclosure summary="Second option" name="demo-exclusive"><p>Opening this closes its sibling.</p></Disclosure>Rich content
More to explore
Continue with a related component.
View TextLinkShow code
---
import Disclosure from '@dhekode/ui/primitives/Disclosure.tsx';
import TextLink from '@dhekode/ui/primitives/TextLink.tsx';
---
<Disclosure summary="More to explore"><p>Continue with a related component.</p><TextLink href="/decoderen/text-link/">View TextLink</TextLink></Disclosure>API reference
summaryType:
stringDefault:
requiredVisible text on the native summary trigger.
openType:
booleanDefault:
falseInitial expanded state; native interaction owns later changes.
nameType:
stringDefault:
unsetA shared name creates a native exclusive group.
indexType:
numberDefault:
unsetOptional decorative index, hidden from assistive technology.
sizeType:
'md' | 'lg'Default:
'md'Default control or larger section treatment.
classNameType:
string | undefinedDefault:
unsetAdds classes to the React component root, after its own utilities. React components take className, not class.
Slots: Default: supporting content, including paragraphs, lists or links.
Omit name for independent disclosures. Use the same name only for mutually exclusive content. FAQ copy and section headings belong to the consuming feature.
Original component source
import type { ReactNode } from 'react';
import Icon from '@dhekode/icons/Icon.tsx';
import { classNames } from '@dhekode/utils/class-names';
import { stateLayer } from '@dhekode/utils/state-layer';
type Size = 'md' | 'lg';
export interface DisclosureProps {
summary: string;
open?: boolean | undefined;
/** Items sharing a name form an exclusive group: opening one closes the others. */
name?: string | undefined;
/** Shows a decorative two-digit number before the summary. */
index?: number | undefined;
size?: Size | undefined;
className?: string | undefined;
children: ReactNode;
}
const sizes: Record<Size, { summary: string; title: string; content: string }> = {
md: { summary: 'py-xs', title: 'text-body leading-snug', content: 'pb-lg' },
// Large summaries read as subheadings: the heading face at h4, medium weight (DESIGN.md).
lg: {
summary: 'py-sm',
title: 'font-heading text-h4 leading-heading tracking-heading',
content: 'pb-xl',
},
};
/**
* Native content disclosure laid out as a Material 3 list item: the row takes the hairline
* dividers, and the trailing chevron sits in a round state layer that answers hover, focus and
* press on the whole summary. The content slides open with the dk-details-reveal recipe from
* @dhekode/styles. Collections and business copy belong to the caller.
*/
export default function Disclosure({
summary,
open = false,
name,
index,
size = 'md',
className,
children,
}: DisclosureProps) {
const indexed = index !== undefined;
return (
<details
className={classNames(
'dk-disclosure dk-details-reveal group border-y-(length:--dk-border-width-hairline) border-solid border-surface-guide wrap-anywhere not-first:border-t-0 open:border-surface-rule',
className,
)}
open={open}
name={name}
data-size={size}
data-indexed={indexed ? '' : undefined}
>
<summary
className={classNames(
'dk-disclosure__summary group/summary flex min-h-(--dk-layout-touch-target) cursor-pointer list-none items-center gap-md',
sizes[size].summary,
)}
>
{/* The number and title share a baseline; the pair centres on the chevron. */}
<span className="flex min-w-0 flex-1 items-baseline gap-md">
{indexed && (
<span
className="dk-label dk-disclosure__index w-xl shrink-0 text-surface-accent"
aria-hidden="true"
>
{String(index).padStart(2, '0')}
</span>
)}
<span
className={classNames(
'dk-disclosure__title min-w-0 flex-1 font-medium transition-colors duration-(--dk-motion-duration-quick) group-hover/summary:text-surface-accent group-open:text-surface-accent',
sizes[size].title,
)}
>
{summary}
</span>
</span>
<span
className={`dk-disclosure__toggle relative grid size-(--dk-layout-button-height) shrink-0 place-items-center rounded-full text-surface-accent before:rounded-full ${stateLayer} group-hover/summary:before:opacity-(--dk-state-layer-hover) group-focus-visible/summary:before:opacity-(--dk-state-layer-focus) group-active/summary:before:opacity-(--dk-state-layer-pressed)`}
aria-hidden="true"
>
<Icon
name="chevron-down"
size={20}
className="dk-disclosure__chevron duration-(--dk-motion-duration-fast) ease-smooth-out group-open:-scale-y-100 motion-safe:transition-transform"
/>
</span>
</summary>
<div
className={classNames(
'dk-disclosure__content dk-details-reveal__content grid max-w-prose gap-md text-surface-muted',
sizes[size].content,
indexed && 'ps-2xl',
)}
>
{children}
</div>
</details>
);
}Best practices
- Keep the summary descriptive and concise.
- Keep essential content visible; disclosures are for supporting detail.
- Preserve native keyboard and focus behavior.
- Keep answers short: content slides open with motion allowed, and opens instantly with reduced motion.