Back to Heroui

Disclosure

apps/docs/content/docs/en/react/components/(navigation)/disclosure.mdx

3.2.33.7 KB
Original Source

Usage

tsx
import { Disclosure } from '@heroui/react';

<ComponentPreview name="disclosure-basic" minHeight="440px" />

Anatomy

tsx
import { Disclosure } from '@heroui/react';

export default () => (
  <Disclosure>
    <Disclosure.Heading>
      <Disclosure.Trigger>
        <Disclosure.Indicator />
      </Disclosure.Trigger>
    </Disclosure.Heading>
    <Disclosure.Content/>
  </Disclosure>
)

Examples

Render Function

<ComponentPreview name="disclosure-render-function" />

Customization

Tailwind CSS

<ComponentPreview name="disclosure-custom-styles" />

Global CSS

To customize the Disclosure component classes, you can use the @layer components directive. Learn more.

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

HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.

CSS Classes

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

Base Classes [!toc]

  • .disclosure - Base container styles
  • .disclosure__heading - Heading wrapper
  • .disclosure__trigger - Trigger button styles
  • .disclosure__indicator - Chevron indicator styles
  • .disclosure__content - Content container with animations

Interactive States

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

  • Expanded: [data-expanded="true"] on indicator for rotation
  • Focus: :focus-visible or [data-focus-visible="true"] on trigger
  • Disabled: :disabled or [aria-disabled="true"] on trigger
  • Hidden: [aria-hidden="false"] on content for visibility

API Reference

Disclosure

PropTypeDefaultDescription
isExpandedbooleanfalseControls the expanded state
onExpandedChange(isExpanded: boolean) => void-Callback when expanded state changes
isDisabledbooleanfalseWhether the disclosure is disabled
childrenReactNode | RenderFunction-Content to render
classNamestring-Additional CSS classes
renderDOMRenderFunction<keyof React.JSX.IntrinsicElements, DisclosureRenderProps>-Overrides the default DOM element with a custom render function.

DisclosureTrigger

PropTypeDefaultDescription
childrenReactNode | RenderFunction-Trigger content
classNamestring-Additional CSS classes

DisclosureContent

PropTypeDefaultDescription
childrenReactNode-Content to show/hide
classNamestring-Additional CSS classes
renderDOMRenderFunction<keyof React.JSX.IntrinsicElements, DisclosureContentRenderProps>-Overrides the default DOM element with a custom render function.

Render Props

When using the render prop pattern, these values are provided:

PropTypeDescription
isExpandedbooleanCurrent expanded state
isDisabledbooleanWhether disclosure is disabled
<RelatedShowcases component="Disclosure" /> <RelatedComponents component="disclosure" />