Morphos
Layout

Disclosure

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

Interactive example

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
openbooleanControlled open state
defaultOpenbooleanfalseInitial open state (uncontrolled)
onOpenChange(open: boolean) => voidCalled when open state changes
classstringCSS class
idstringHTML id

Methods — Disclosure

MethodDescription
toggle()Toggles the disclosure open/closed

Props — DisclosureTrigger

PropTypeDefaultDescription
disclosureDisclosureThe Disclosure state instance
childrenChildrenTrigger label
classstringCSS class
idstringHTML id
aria-labelstringAccessible label when trigger text is not descriptive

Props — DisclosureContent

PropTypeDefaultDescription
disclosureDisclosureThe Disclosure state instance
childrenChildrenContent to reveal
classstringCSS class
idstringHTML 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