Components
Collapsible
One trigger that shows and hides one region of content.
Client component ("use client")
import.tsx
collapsible-basic.tsx
collapsible-controlled.tsx
Edit on GitHubNot 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 { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@neshel-ui/components";Usage
Preview: collapsible-basic
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
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | — |
| defaultOpen | boolean | false | Initial open state when uncontrolled (default false). |
| disabled | boolean | — | Ignore user interaction (the trigger is disabled). |
| onOpenChange | (open: boolean) => void | — | — |
| open | boolean | — | Controlled open state. |
| ref | Ref<HTMLDivElement> | — | — |
Also accepts the props of: React DOM attributes.
CollapsibleTriggerProps
| Prop | Type | Default | Description |
|---|---|---|---|
| asChild | boolean | — | Render the single child element as the trigger (it must render a <button>). |
| children | ReactNode | — | — |
| ref | Ref<HTMLButtonElement> | — | — |
Also accepts the props of: React DOM attributes.
CollapsibleContentProps
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | — |
| hiddenUntilFound | boolean | — | Closed panel uses hidden="until-found" so in-page search can open it (implies keepMounted). |
| keepMounted | boolean | — | Keep the closed panel in the DOM (hidden). Default false: unmounted when closed. |
| ref | Ref<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
The filters keep their values while hidden.
"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-expandedandaria-controls;asChildmust render a button. disableddisables the trigger.- The optional height transition stops under
prefers-reduced-motion.
Keyboard
| Key | Action |
|---|---|
| Enter / Space | Toggle the content |
| Tab | Move 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.