Skip to Content
Neshel-UI
Components

Collapsible

One trigger that shows and hides one region of content.

Client component ("use client")

Not in 0.1.0 yet

This API is on the main branch but not in the 0.1.0 packages on npm. To use it today, install locally packed tarballs.

Purpose

Collapsible reveals optional detail ("Show more", advanced filters). It is a single disclosure, not a one-item Accordion: there is no heading, group or value.

Import

import.tsx
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@neshel-ui/components";

Usage

Preview: collapsible-basic
Preview theme
collapsible-basic.tsx
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@neshel-ui/components";

export default function CollapsibleBasic() {
  return (
    <Collapsible>
      <CollapsibleTrigger>Show release notes</CollapsibleTrigger>
      <CollapsibleContent>
        <p>Accordion, Collapsible, Switch and Toast are now part of the components.</p>
      </CollapsibleContent>
    </Collapsible>
  );
}

API

CollapsibleProps

CollapsibleProps
PropTypeDefaultDescription
childrenReactNode——
defaultOpenbooleanfalseInitial open state when uncontrolled (default false).
disabledboolean—Ignore user interaction (the trigger is disabled).
onOpenChange(open: boolean) => void——
openboolean—Controlled open state.
refRef<HTMLDivElement>——

Also accepts the props of: React DOM attributes.

CollapsibleTriggerProps

CollapsibleTriggerProps
PropTypeDefaultDescription
asChildboolean—Render the single child element as the trigger (it must render a <button>).
childrenReactNode——
refRef<HTMLButtonElement>——

Also accepts the props of: React DOM attributes.

CollapsibleContentProps

CollapsibleContentProps
PropTypeDefaultDescription
childrenReactNode——
hiddenUntilFoundboolean—Closed panel uses hidden="until-found" so in-page search can open it (implies keepMounted).
keepMountedboolean—Keep the closed panel in the DOM (hidden). Default false: unmounted when closed.
refRef<HTMLDivElement>——

Also accepts the props of: React DOM attributes.

Controlled and uncontrolled

open, defaultOpen and onOpenChange, like Dialog. Closed content is unmounted unless keepMounted (hidden) or hiddenUntilFound is set.

Preview: collapsible-controlled
Preview theme
collapsible-controlled.tsx
"use client";
import { Button, Collapsible, CollapsibleContent, CollapsibleTrigger } from "@neshel-ui/components";
import { useState } from "react";

export default function CollapsibleControlled() {
  const [open, setOpen] = useState(false);
  return (
    <Collapsible open={open} onOpenChange={setOpen}>
      <CollapsibleTrigger asChild>
        <Button variant="outline">{open ? "Hide filters" : "Show filters"}</Button>
      </CollapsibleTrigger>
      <CollapsibleContent keepMounted>
        <p style={{ paddingTop: 12 }}>The filters keep their values while hidden.</p>
      </CollapsibleContent>
    </Collapsible>
  );
}

Accessibility

  • The trigger is a native button with aria-expanded and aria-controls; asChild must render a button.
  • disabled disables the trigger.
  • The optional height transition stops under prefers-reduced-motion.

Keyboard

KeyAction
Enter / SpaceToggle the content
TabMove focus as usual

Limitations

Content that is unmounted while closed loses its state (form drafts, scroll position). Use keepMounted when it must survive.

Common mistakes

  • Several Collapsibles as an FAQ: use Accordion, which adds headings and arrow keys.
  • A trigger whose text does not say what it opens.
Edit on GitHub

On this page