Morphos
Layout

Disclosure

A single collapsible section that shows or hides content when a trigger is activated.

Interactive example

Open in Storybook

Installation

npm install @morphos/layout
pnpm add @morphos/layout
yarn add @morphos/layout
bun add @morphos/layout

Import

import { Disclosure, DisclosureTrigger, DisclosureContent } from '@morphos/layout'

Usage

@Component()
class MyComponent extends StatefulComponent {
  @State() disclosure = new Disclosure({ defaultOpen: false })

  render() {
    return (
      <Disclosure disclosure={this.disclosure}>
        <DisclosureTrigger disclosure={this.disclosure}>
          Show details
        </DisclosureTrigger>
        <DisclosureContent disclosure={this.disclosure}>
          <p>This content is revealed when the trigger is activated.</p>
        </DisclosureContent>
      </Disclosure>
    )
  }
}

Aliases

Disclosure, DisclosureTrigger, and DisclosureContent are also exported as Collapsible, CollapsibleTrigger, and CollapsibleContent — they are the exact same classes, just re-exported under alternate names for consumers who prefer that naming.

import { Collapsible, CollapsibleTrigger, CollapsibleContent } from '@morphos/layout'

Compound components

ComponentDescription
DisclosureRoot state manager — controls open state
DisclosureTriggerThe button that toggles content visibility
DisclosureContentThe collapsible content area

Props — Disclosure

PropTypeDefaultDescription
openboolean—Controlled open state
defaultOpenbooleanfalseInitial open state (uncontrolled)
onOpenChange(open: boolean) => void—Called when open state changes
classstring—CSS class
idstring—HTML id
childrenChildren—Content — typically a DisclosureTrigger and DisclosureContent

Methods — Disclosure

MethodDescription
toggle()Toggles the disclosure open/closed

Props — DisclosureTrigger

PropTypeDefaultDescription
disclosureDisclosure—The Disclosure state instance
childrenChildren—Trigger label
classstring—CSS class
idstring—HTML id
aria-labelstring—Accessible label when trigger text is not descriptive

Props — DisclosureContent

PropTypeDefaultDescription
disclosureDisclosure—The Disclosure state instance
childrenChildren—Content to reveal
classstring—CSS class
idstring—HTML id (defaults to the disclosure's generated content id)

data-* attributes

AttributeElementWhen present
data-openDisclosure, DisclosureTrigger, DisclosureContentContent is visible

DisclosureContent uses the native hidden attribute to hide content when closed, which removes it from the accessibility tree and prevents focus from reaching hidden elements.

Styling example

.morphos-disclosure-trigger[data-open]::before {
  transform: rotate(-135deg);
}

On this page