PeakUI

Disclosure

A collapsible section with a heading and a trigger

Usage

import {Disclosure} from "@peakui/react";

Anatomy

import {Disclosure} from "@peakui/react";

export default () => (
  <Disclosure>
    <Disclosure.Heading>
      <Disclosure.Trigger>
        <Disclosure.Indicator />
      </Disclosure.Trigger>
    </Disclosure.Heading>
    <Disclosure.Content>
      <Disclosure.Body>Panel content</Disclosure.Body>
    </Disclosure.Content>
  </Disclosure>
);

Examples

Render Function

render on the root and on Disclosure.Content replaces the rendered element while keeping the disclosure contract.

Customization

Tailwind CSS

Utilities on className restyle each part; the trigger keeps its focus and disabled states.

<Disclosure.Trigger className="flex w-full items-center justify-between rounded-md border px-4 py-2 text-start hover:bg-gray-50">
  <span>Toggle content</span>
  <Disclosure.Indicator />
</Disclosure.Trigger>

Global CSS

@layer components {
  .disclosure {
    @apply relative;
  }

  .disclosure__trigger {
    @apply cursor-pointer;
  }

  .disclosure__indicator {
    @apply transition-transform duration-300;
  }

  .disclosure__content {
    @apply overflow-hidden transition-all;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The Disclosure component uses these CSS classes (view source styles):

Base Classes

  • .disclosure - Base container styles
  • .disclosure__heading - Heading wrapper
  • .disclosure__trigger - Trigger button styles
  • .disclosure__indicator - Chevron indicator styles
  • .disclosure__content - Content container with animations
  • .disclosure__body - Panel body padding
  • .disclosure__body-inner - Inner wrapper receiving the consumer className

Slots

  • [data-slot="disclosure"] - The root element
  • [data-slot="disclosure-heading"] - The heading element
  • [data-slot="disclosure-trigger"] - The trigger button
  • [data-slot="disclosure-content"] - The collapsible panel
  • [data-slot="disclosure-body"] - The body wrapper
  • [data-slot="disclosure-body-inner"] - The inner body wrapper
  • [data-slot="disclosure-indicator"] - The chevron indicator

Interactive States

The component supports both CSS pseudo-classes and data attributes:

  • Expanded: [data-expanded="true"] on the root, the panel and the indicator
  • Focus: :focus-visible or [data-focus-visible="true"] on the trigger
  • Disabled: :disabled or [aria-disabled="true"] on the trigger
  • Hidden: hidden="until-found" on the collapsed panel, set by React Aria

API Reference

Disclosure

PropTypeDefaultDescription
isExpandedboolean-Controls the expanded state
defaultExpandedboolean-Expands the panel on first render
onExpandedChange(isExpanded: boolean) => void-Callback when the expanded state changes
isDisabledbooleanfalseWhether the disclosure is disabled
idKey-The id used for group membership in a DisclosureGroup
childrenReactNode | ((values: DisclosureRenderProps) => ReactNode)-Content to render, or a function of the render props
classNamestring | ((values: DisclosureRenderProps) => string)-Additional classes, or a function of the render props
renderDOMRenderFunction<'div', DisclosureRenderProps>-Replaces the rendered element with your own

Every other attribute of a <div> is accepted.

Disclosure.Heading

PropTypeDefaultDescription
levelnumber3The heading level
childrenReactNode-The heading content
classNamestring-Additional classes
renderDOMRenderFunction<'h1', undefined>-Replaces the rendered heading with your own

Every other attribute of an <h3> is accepted.

Disclosure.Trigger

PropTypeDefaultDescription
childrenReactNode | ((values: ButtonRenderProps) => ReactNode)-Trigger content, or a function of the render props
classNamestring | ((values: ButtonRenderProps) => string)-Additional classes, or a function of the render props

Every React Aria Button attribute is accepted.

Disclosure.Content

PropTypeDefaultDescription
childrenReactNode-Content to show and hide
classNamestring | ((values: DisclosurePanelRenderProps) => string)-Additional classes, or a function of the render props
renderDOMRenderFunction<'div', DisclosurePanelRenderProps>-Replaces the rendered panel with your own

Every other attribute of a <div> is accepted.

Disclosure.Body

PropTypeDefaultDescription
childrenReactNode-The body content
classNamestring-Additional classes, applied to the inner wrapper

Every other attribute of a <div> is accepted.

Disclosure.Indicator

PropTypeDefaultDescription
childrenReactNode-Replaces the built-in chevron <svg>
classNamestring-Additional classes

Every other attribute of an <svg> is accepted.

Render Props

PropTypeDescription
children(values: DisclosureRenderProps) => ReactNodeReceives isExpanded, isDisabled, isFocusVisibleWithin, state
className(values: DisclosureRenderProps) => stringSame values as children

On this page