Collapsible

A button that shows and hides one region of content. For a set of headed sections, use Accordion.

BetaSource

Import

import { Collapsible } from "@meridui/react";

Anatomy

<Collapsible.Root>
  <Collapsible.Trigger />
  <Collapsible.Content />
</Collapsible.Root>
  • Root holds the open state and renders a <div>.
  • Trigger is a <button> with aria-expanded and aria-controls. With asChild it merges onto your own button.
  • Content is the region; it is hidden while closed and unmounts its children unless forceMount.

Examples

Controlled, with your own button

API reference

Root

Accepts every <div> attribute.

PropTypeDefaultDescription
openboolean–Controlled open state.
defaultOpenbooleanfalseInitial open state when uncontrolled.
onOpenChange(open: boolean) => void–Called when the open state should change.
disabledbooleanfalsePrevent toggling; the trigger is disabled.
refRef<HTMLDivElement>–Forwarded ref to the root.

Trigger

Accepts every <button> attribute.

PropTypeDefaultDescription
asChildbooleanfalseRender the single child element instead of a <button>, merging props, ref and handlers.
refRef<HTMLButtonElement>–Forwarded ref to the button.

Content

Accepts every <div> attribute.

PropTypeDefaultDescription
forceMountbooleanfalseKeep children mounted (hidden) while closed, e.g. to keep form state or allow find-in-page.
refRef<HTMLDivElement>–Forwarded ref to the region.

Styling

ClassElement
.mrd-collapsibleRoot
.mrd-collapsible__triggerTrigger (unless asChild)
.mrd-collapsible__contentContent
AttributeOnValues
data-stateRoot, Trigger, Contentopen, closed
data-disabledRoot, Triggerpresent when disabled

Accessibility

Follows the WAI-ARIA Disclosure pattern. The trigger is a real button, so it works with Enter and Space and is announced with its expanded state.

KeyAction
EnterToggle the region.
SpaceToggle the region.

Guidelines

Do

Say what will be shown: "Show build details", "Show 3 more repositories".

Avoid

Hide required form fields or error messages in a collapsed region.

  • Accordion: several headed sections.
  • Tabs: switch between panels of equal weight.